Decompiled source of KsmPlushToy v1.4.0

BepInEx/plugins/KsmPlush/KsmPlush.Shared.dll

Decompiled a day ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Text;
using GameNetcodeStuff;
using Unity.Collections;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace KsmPlush;

public class PlushBehaviour : PhysicsProp
{
	private class FrozenEnemy
	{
		public float speed;

		public Transform visual;

		public Vector3 baseScale = Vector3.one;

		public float phase;
	}

	public AudioSource musicSource;

	public Transform model;

	public float danceRadius = 15f;

	public float heldDanceRadius = 6f;

	public float enemyRadius = 15f;

	public float tickInterval = 0.2f;

	public int emoteNumber = 1;

	public float enemySpinDegreesPerSecond = 392.727f;

	public bool musicOn;

	public AudioClip[] playlist;

	public int trackIndex;

	public float radiusOverride;

	public float weightOverride;

	private bool musicPaused;

	private float lastTrackSwitch;

	public static Func<string> ConfigNextKey;

	private static Key cachedNextKey = (Key)0;

	private static string cachedNextKeyName;

	public bool deafenDogsWhileSinging = true;

	public bool enemyDance = true;

	public float dogDeafenRadius = 45f;

	public static bool logVerbose = true;

	public static Func<float> ConfigDanceRadius;

	public static Func<float> ConfigHeldDanceRadius;

	public static Func<float> ConfigEnemyRadius;

	public static Func<float> ConfigEnemySpinSpeed;

	public static Func<bool> ConfigEnemyQBounce;

	public static Func<bool> ConfigEnemyDance;

	public bool enemyQBounce = true;

	public static Func<bool> ConfigTooManyEmotes;

	public static Func<float> ConfigDanceChangeInterval;

	public static Func<float> ConfigVolume;

	public static Func<bool> ConfigMute;

	public static Func<string> ConfigEnemyFilter;

	public static Func<bool> ConfigEnableUI;

	public static Func<bool> ConfigHostSync;

	private bool firstUpdateLogged;

	private const string FilterMessage = "KsmPlushEnemyFilter";

	private string hostFilterCsv;

	private static string filterRaw;

	private static readonly HashSet<string> filterSet = new HashSet<string>();

	private Vector3 baseModelPos;

	private Quaternion baseModelRot = Quaternion.identity;

	private Vector3 baseModelScale = Vector3.one;

	private bool hasBase;

	private float phase;

	private float timer;

	private int lastHeldState = -1;

	private bool dancing;

	private readonly Dictionary<EnemyAI, FrozenEnemy> frozenSpeeds = new Dictionary<EnemyAI, FrozenEnemy>();

	private const float QPeriod = 11f / 12f;

	private static readonly float[] QTimes = new float[5]
	{
		0f,
		5f / 22f,
		0.5f,
		17f / 22f,
		1f
	};

	private static readonly float[] QHorizontal = new float[5] { 1f, 1.2f, 0.9f, 1f, 1f };

	private static readonly float[] QVertical = new float[5] { 1f, 0.8f, 1.1f, 1f, 1f };

	private readonly List<EnemyAI> toRelease = new List<EnemyAI>();

	private readonly List<PlayerControllerB> vanillaDancers = new List<PlayerControllerB>();

	private static FieldInfo dogHearCooldown;

	private static bool dogFieldChecked;

	private static bool tmeChecked;

	private static bool tmeAvailable;

	private static Type tmeControllerType;

	private static Type tmeEmoteType;

	private static PropertyInfo tmeLocalProp;

	private static MethodInfo tmePerform;

	private static MethodInfo tmeStop;

	private static FieldInfo tmeAllEmotes;

	private static FieldInfo tmeEmotePose;

	private static FieldInfo tmeEmoteNeedsProp;

	private static FieldInfo tmeEmoteName;

	private readonly List<object> tmeDriven = new List<object>();

	private int tmeSlot = int.MinValue;

	private string lastTmeName = "";

	private bool startedOnce;

	private int framesSinceSpawn;

	private bool EnemyDance
	{
		get
		{
			if (ConfigEnemyDance == null)
			{
				return enemyDance;
			}
			return ConfigEnemyDance();
		}
	}

	private static float QEval(float loop01, float[] values)
	{
		loop01 -= Mathf.Floor(loop01);
		for (int i = 1; i < QTimes.Length; i++)
		{
			if (loop01 <= QTimes[i] || i == QTimes.Length - 1)
			{
				float num = QTimes[i - 1];
				float num2 = QTimes[i];
				float num3 = ((num2 > num) ? Mathf.Clamp01((loop01 - num) / (num2 - num)) : 0f);
				num3 = num3 * num3 * (3f - 2f * num3);
				return Mathf.Lerp(values[i - 1], values[i], num3);
			}
		}
		return values[^1];
	}

	public override void Start()
	{
		//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_0089: 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_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_01ae: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b3: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)("[KsmPlush] Start enter (already=" + startedOnce + ")"));
		if (startedOnce)
		{
			return;
		}
		startedOnce = true;
		((GrabbableObject)this).Start();
		Debug.Log((object)"[KsmPlush] base.Start done");
		if ((Object)(object)model == (Object)null)
		{
			model = ((Component)this).transform.Find("Model");
		}
		if ((Object)(object)model != (Object)null)
		{
			baseModelPos = model.localPosition;
			baseModelRot = model.localRotation;
			baseModelScale = model.localScale;
			hasBase = true;
		}
		if (weightOverride > 0.01f && (Object)(object)((GrabbableObject)this).itemProperties != (Object)null)
		{
			((GrabbableObject)this).itemProperties.weight = weightOverride;
			Debug.Log((object)("[KsmPlush] runtime weight=" + ((GrabbableObject)this).itemProperties.weight));
		}
		if ((Object)(object)musicSource == (Object)null)
		{
			musicSource = ((Component)this).GetComponent<AudioSource>();
		}
		if ((Object)(object)musicSource != (Object)null)
		{
			musicSource.playOnAwake = false;
			musicSource.loop = true;
			musicSource.spatialBlend = 1f;
			musicSource.rolloffMode = (AudioRolloffMode)1;
			musicSource.minDistance = 2f;
			musicSource.maxDistance = 30f;
			musicSource.dopplerLevel = 0f;
		}
		bool flag = ConfigHostSync == null || ConfigHostSync();
		Debug.Log((object)("[KsmPlush] spawn start sync=" + flag + " pos=" + ((object)((Component)this).transform.position/*cast due to .constrained prefix*/).ToString()));
		try
		{
			if (flag)
			{
				RegisterFilterSync();
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[KsmPlush] filter sync register failed: " + ex));
		}
		Diag("Start");
		if (logVerbose)
		{
			DumpHierarchy();
		}
		VisualFix.Apply(((Component)this).gameObject, "start");
		Debug.Log((object)"[KsmPlush] Start complete");
	}

	private void DumpHierarchy()
	{
		//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_0029: Unknown result type (might be due to invalid IL or missing references)
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Unknown result type (might be due to invalid IL or missing references)
		//IL_025f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0264: Unknown result type (might be due to invalid IL or missing references)
		//IL_0268: Unknown result type (might be due to invalid IL or missing references)
		//IL_026d: Unknown result type (might be due to invalid IL or missing references)
		//IL_028f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0294: Unknown result type (might be due to invalid IL or missing references)
		//IL_02b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bb: Unknown result type (might be due to invalid IL or missing references)
		Debug.Log((object)("[KsmPlush][dump] rootScale=" + ((object)((Component)this).transform.localScale/*cast due to .constrained prefix*/).ToString() + " rootPos=" + ((object)((Component)this).transform.position/*cast due to .constrained prefix*/).ToString()));
		Renderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<Renderer>(true);
		Debug.Log((object)("[KsmPlush][dump] renderers=" + componentsInChildren.Length));
		Renderer[] array = componentsInChildren;
		foreach (Renderer val in array)
		{
			string text = (((Object)(object)val.sharedMaterial == (Object)null || (Object)(object)val.sharedMaterial.shader == (Object)null) ? "null" : ((Object)val.sharedMaterial.shader).name);
			string text2 = "none";
			MeshFilter component = ((Component)val).GetComponent<MeshFilter>();
			Bounds bounds;
			if ((Object)(object)component != (Object)null && (Object)(object)component.sharedMesh != (Object)null)
			{
				string[] obj = new string[5]
				{
					((Object)component.sharedMesh).name,
					" v=",
					component.sharedMesh.vertexCount.ToString(),
					" mb=",
					null
				};
				bounds = component.sharedMesh.bounds;
				obj[4] = ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString();
				text2 = string.Concat(obj);
			}
			SkinnedMeshRenderer val2 = (SkinnedMeshRenderer)(object)((val is SkinnedMeshRenderer) ? val : null);
			if ((Object)(object)val2 != (Object)null && (Object)(object)val2.sharedMesh != (Object)null)
			{
				text2 = "skinned " + ((Object)val2.sharedMesh).name + " v=" + val2.sharedMesh.vertexCount;
			}
			string[] obj2 = new string[20]
			{
				"[KsmPlush][dump] ",
				((Object)val).name,
				" type=",
				((object)val).GetType().Name,
				" enabled=",
				val.enabled.ToString(),
				" layer=",
				((Component)val).gameObject.layer.ToString(),
				" mat=",
				((Object)(object)val.sharedMaterial == (Object)null) ? "null" : ((Object)val.sharedMaterial).name,
				" shader=",
				text,
				" mesh=",
				text2,
				" wb=",
				null,
				null,
				null,
				null,
				null
			};
			bounds = val.bounds;
			obj2[15] = ((object)((Bounds)(ref bounds)).size/*cast due to .constrained prefix*/).ToString();
			obj2[16] = " localPos=";
			obj2[17] = ((object)((Component)val).transform.localPosition/*cast due to .constrained prefix*/).ToString();
			obj2[18] = " localScale=";
			obj2[19] = ((object)((Component)val).transform.localScale/*cast due to .constrained prefix*/).ToString();
			Debug.Log((object)string.Concat(obj2));
		}
	}

	private void Diag(string tag)
	{
		if (logVerbose)
		{
			Debug.Log((object)("[KsmPlush][" + tag + "] held=" + ((GrabbableObject)this).isHeld + " heldBy=" + (((Object)(object)((GrabbableObject)this).playerHeldBy == (Object)null) ? "null" : ((GrabbableObject)this).playerHeldBy.playerUsername) + " musicOn=" + musicOn + " grabbable=" + ((GrabbableObject)this).grabbable + " layer=" + ((Component)this).gameObject.layer));
		}
	}

	private float GroundRadius()
	{
		if (radiusOverride > 0.5f)
		{
			return radiusOverride;
		}
		float num = ((ConfigDanceRadius != null) ? ConfigDanceRadius() : danceRadius);
		if (!(num <= 0.5f))
		{
			return num;
		}
		return 0.5f;
	}

	private float HeldRadius()
	{
		float num = ((ConfigHeldDanceRadius != null) ? ConfigHeldDanceRadius() : heldDanceRadius);
		if (!(num <= 0.5f))
		{
			return num;
		}
		return 0.5f;
	}

	private float EnemyRadius()
	{
		if (radiusOverride > 0.5f)
		{
			return radiusOverride;
		}
		float num = ((ConfigEnemyRadius != null) ? ConfigEnemyRadius() : enemyRadius);
		if (!(num <= 0.5f))
		{
			return num;
		}
		return 0.5f;
	}

	private float SpinSpeed()
	{
		if (ConfigEnemySpinSpeed == null)
		{
			return enemySpinDegreesPerSecond;
		}
		return ConfigEnemySpinSpeed();
	}

	private float DanceInterval()
	{
		float num = ((ConfigDanceChangeInterval != null) ? ConfigDanceChangeInterval() : 6f);
		if (!(num < 1f))
		{
			return num;
		}
		return 1f;
	}

	private Vector3 Anchor()
	{
		//IL_0025: 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)
		if ((Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null)
		{
			return ((Component)((GrabbableObject)this).playerHeldBy).transform.position;
		}
		return ((Component)this).transform.position;
	}

	public override void ItemActivate(bool used, bool buttonDown = true)
	{
		((GrabbableObject)this).ItemActivate(used, buttonDown);
		if (!buttonDown)
		{
			return;
		}
		bool flag = playlist != null && playlist.Length > 1;
		if (!musicOn)
		{
			musicPaused = false;
			if (flag)
			{
				trackIndex = Mathf.Clamp(trackIndex, 0, playlist.Length - 1);
			}
			lastTrackSwitch = Time.time;
			SetMusic(on: true);
			Debug.Log((object)("[KsmPlush] play" + (flag ? (" track " + (trackIndex + 1) + "/" + playlist.Length) : "")));
			Tip(flag ? ("♪ " + (trackIndex + 1) + "/" + playlist.Length + "(左键暂停)") : "♪ 唱歌中(左键暂停)");
		}
		else if (!musicPaused)
		{
			musicPaused = true;
			if ((Object)(object)musicSource != (Object)null && musicSource.isPlaying)
			{
				musicSource.Pause();
			}
			ReleaseAll();
			ResetModel();
			((GrabbableObject)this).isBeingUsed = false;
			Debug.Log((object)"[KsmPlush] paused");
			Tip("暂停(左键继续)");
		}
		else
		{
			musicPaused = false;
			((GrabbableObject)this).isBeingUsed = true;
			ApplyMusic();
			timer = 0f;
			Debug.Log((object)"[KsmPlush] resumed");
			Tip("继续(左键暂停)");
		}
	}

	public void NextTrack()
	{
		if (playlist != null && playlist.Length > 1)
		{
			trackIndex = (trackIndex + 1) % playlist.Length;
			lastTrackSwitch = Time.time;
			musicPaused = false;
			musicOn = true;
			((GrabbableObject)this).isBeingUsed = true;
			ApplyMusic();
			timer = 0f;
			Debug.Log((object)("[KsmPlush] next track " + (trackIndex + 1) + "/" + playlist.Length));
			Tip("♪ " + (trackIndex + 1) + "/" + playlist.Length + "(F 下一首)");
		}
	}

	private static Key ParseNextKey(string name)
	{
		//IL_0059: 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_005f: 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_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		if (string.IsNullOrEmpty(name))
		{
			return (Key)0;
		}
		name = name.Trim();
		if (name == cachedNextKeyName)
		{
			return cachedNextKey;
		}
		Key result = (Key)0;
		try
		{
			result = (Key)Enum.Parse(typeof(Key), name, ignoreCase: true);
		}
		catch
		{
			Debug.LogWarning((object)("[KsmPlush] unknown next-track key: " + name));
		}
		cachedNextKeyName = name;
		cachedNextKey = result;
		return result;
	}

	private void Tip(string text)
	{
		HUDManager instance = HUDManager.Instance;
		if ((Object)(object)instance != (Object)null)
		{
			instance.DisplayTip("Ksm Plush", text, false, false, "LC_Tip1");
		}
	}

	private void SetMusic(bool on)
	{
		musicOn = on;
		((GrabbableObject)this).isBeingUsed = on;
		if (on)
		{
			musicPaused = false;
		}
		ApplyMusic();
		if (!on)
		{
			ReleaseAll();
			ResetModel();
		}
		else
		{
			tmeSlot = int.MinValue;
			timer = 0f;
			RequestFilterSync();
		}
	}

	private bool Singing()
	{
		if (musicOn)
		{
			return !musicPaused;
		}
		return false;
	}

	private void ApplyMusic()
	{
		if ((Object)(object)musicSource == (Object)null)
		{
			return;
		}
		bool flag = ConfigMute != null && ConfigMute();
		float num = ((ConfigVolume != null) ? ConfigVolume() : 0.9f);
		musicSource.mute = flag;
		musicSource.volume = (flag ? 0f : Mathf.Clamp01(num));
		bool flag2 = playlist != null && playlist.Length > 1;
		musicSource.loop = !flag2;
		if (!musicOn)
		{
			if (musicSource.isPlaying)
			{
				musicSource.Stop();
			}
			return;
		}
		if (playlist != null && playlist.Length != 0)
		{
			AudioClip val = playlist[Mathf.Clamp(trackIndex, 0, playlist.Length - 1)];
			if ((Object)(object)val != (Object)null && (Object)(object)musicSource.clip != (Object)(object)val)
			{
				musicSource.clip = val;
				musicSource.time = 0f;
			}
		}
		if (musicPaused)
		{
			if (musicSource.isPlaying)
			{
				musicSource.Pause();
			}
		}
		else if (!musicSource.isPlaying)
		{
			if (musicSource.time > 0.05f)
			{
				musicSource.UnPause();
			}
			else
			{
				musicSource.Play();
			}
		}
	}

	public override void Update()
	{
		//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_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0179: Unknown result type (might be due to invalid IL or missing references)
		//IL_0203: Unknown result type (might be due to invalid IL or missing references)
		//IL_0208: Unknown result type (might be due to invalid IL or missing references)
		//IL_0274: Unknown result type (might be due to invalid IL or missing references)
		//IL_024f: Unknown result type (might be due to invalid IL or missing references)
		//IL_025e: Unknown result type (might be due to invalid IL or missing references)
		if (!startedOnce)
		{
			return;
		}
		framesSinceSpawn++;
		if (framesSinceSpawn <= 6 || framesSinceSpawn % 300 == 0)
		{
			Debug.Log((object)("[KsmPlush] tick n=" + framesSinceSpawn + " frame=" + Time.frameCount + " held=" + ((GrabbableObject)this).isHeld + " music=" + musicOn + " pos=" + ((object)((Component)this).transform.position/*cast due to .constrained prefix*/).ToString()));
		}
		if (musicOn && !musicPaused && playlist != null && playlist.Length > 1 && (Object)(object)musicSource != (Object)null && !musicSource.isPlaying && Time.time - lastTrackSwitch > 0.3f)
		{
			trackIndex = (trackIndex + 1) % playlist.Length;
			lastTrackSwitch = Time.time;
			ApplyMusic();
		}
		if (((GrabbableObject)this).isHeld && (Object)(object)((GrabbableObject)this).playerHeldBy != (Object)null && ConfigNextKey != null)
		{
			Key val = ParseNextKey(ConfigNextKey());
			Keyboard current = Keyboard.current;
			if ((int)val != 0 && current != null && ((ButtonControl)current[val]).wasPressedThisFrame)
			{
				NextTrack();
			}
		}
		((GrabbableObject)this).Update();
		if (!firstUpdateLogged)
		{
			firstUpdateLogged = true;
			Debug.Log((object)"[KsmPlush] first update frame reached");
		}
		int num = (((GrabbableObject)this).isHeld ? 1 : 0);
		if (num != lastHeldState)
		{
			lastHeldState = num;
			Diag((num == 1) ? "picked" : "dropped");
		}
		ApplyMusic();
		if (!Singing())
		{
			if (dancing)
			{
				ReleaseAll();
				ResetModel();
			}
			return;
		}
		Vector3 anchor = Anchor();
		AnimateDance();
		SpinFrozenEnemies();
		timer -= Time.deltaTime;
		if (timer <= 0f)
		{
			timer = tickInterval;
			if (deafenDogsWhileSinging)
			{
				KeepDogsDeaf();
			}
			ApplyEnemies(anchor);
			if (!TmeActive())
			{
				ApplyVanillaPlayers(anchor);
			}
			dancing = true;
		}
		if (TmeActive())
		{
			TmeTick(anchor);
		}
	}

	private void KeepDogsDeaf()
	{
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_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_0096: 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)
		if (!dogFieldChecked)
		{
			dogFieldChecked = true;
			dogHearCooldown = typeof(MouthDogAI).GetField("hearNoiseCooldown", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		}
		if (dogHearCooldown == null)
		{
			return;
		}
		RoundManager instance = RoundManager.Instance;
		if ((Object)(object)instance == (Object)null || instance.SpawnedEnemies == null)
		{
			return;
		}
		Vector3 position = ((Component)this).transform.position;
		float num = dogDeafenRadius * dogDeafenRadius;
		for (int i = 0; i < instance.SpawnedEnemies.Count; i++)
		{
			EnemyAI obj = instance.SpawnedEnemies[i];
			MouthDogAI val = (MouthDogAI)(object)((obj is MouthDogAI) ? obj : null);
			if (!((Object)(object)val == (Object)null))
			{
				Vector3 val2 = ((Component)val).transform.position - position;
				if (!(((Vector3)(ref val2)).sqrMagnitude > num))
				{
					dogHearCooldown.SetValue(val, 0.4f);
				}
			}
		}
	}

	private void AnimateDance()
	{
		//IL_0061: 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_007e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0083: Unknown result type (might be due to invalid IL or missing references)
		//IL_0088: 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_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)
		if (!((Object)(object)model == (Object)null) && hasBase)
		{
			phase += Time.deltaTime / (11f / 12f);
			float num = phase - Mathf.Floor(phase);
			float num2 = QEval(num, QHorizontal);
			float num3 = QEval(num, QVertical);
			model.localPosition = baseModelPos;
			model.localRotation = baseModelRot * Quaternion.AngleAxis(num * 360f, Vector3.up);
			model.localScale = Vector3.Scale(baseModelScale, new Vector3(num2, num3, num2));
		}
	}

	private void ResetModel()
	{
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		//IL_002f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)model == (Object)null) && hasBase)
		{
			model.localPosition = baseModelPos;
			model.localRotation = baseModelRot;
			model.localScale = baseModelScale;
		}
	}

	private void SpinFrozenEnemies()
	{
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_010d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0112: Unknown result type (might be due to invalid IL or missing references)
		if (frozenSpeeds.Count == 0)
		{
			return;
		}
		float num = SpinSpeed();
		if (Mathf.Abs(num) < 0.01f)
		{
			return;
		}
		float num2 = num * Time.deltaTime;
		float deltaTime = Time.deltaTime;
		bool flag = ((ConfigEnemyQBounce != null) ? ConfigEnemyQBounce() : enemyQBounce);
		foreach (KeyValuePair<EnemyAI, FrozenEnemy> frozenSpeed in frozenSpeeds)
		{
			FrozenEnemy value = frozenSpeed.Value;
			if (!((Object)(object)frozenSpeed.Key == (Object)null) && value != null)
			{
				((Component)frozenSpeed.Key).transform.Rotate(0f, num2, 0f, (Space)0);
				if (!((Object)(object)value.visual == (Object)null) && flag)
				{
					value.phase += deltaTime / (11f / 12f);
					float loop = value.phase - Mathf.Floor(value.phase);
					float num3 = QEval(loop, QHorizontal);
					float num4 = QEval(loop, QVertical);
					value.visual.localScale = Vector3.Scale(value.baseScale, new Vector3(num3, num4, num3));
				}
			}
		}
	}

	private static Transform FindVisual(Transform root)
	{
		Transform val = null;
		for (int i = 0; i < root.childCount; i++)
		{
			Transform child = root.GetChild(i);
			if (!((Object)(object)child == (Object)null))
			{
				if ((Object)(object)((Component)child).GetComponentInChildren<SkinnedMeshRenderer>(true) != (Object)null)
				{
					return child;
				}
				if ((Object)(object)val == (Object)null && (Object)(object)((Component)child).GetComponentInChildren<Renderer>(true) != (Object)null)
				{
					val = child;
				}
			}
		}
		return val;
	}

	private void RegisterFilterSync()
	{
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0035: Expected O, but got Unknown
		try
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (!((Object)(object)singleton == (Object)null) && singleton.CustomMessagingManager != null)
			{
				singleton.CustomMessagingManager.RegisterNamedMessageHandler("KsmPlushEnemyFilter", new HandleNamedMessageDelegate(OnFilterMessage));
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[KsmPlush] filter sync register failed: " + ex.Message));
		}
	}

	public override void OnDestroy()
	{
		try
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if ((Object)(object)singleton != (Object)null && singleton.CustomMessagingManager != null)
			{
				singleton.CustomMessagingManager.UnregisterNamedMessageHandler("KsmPlushEnemyFilter");
			}
		}
		catch
		{
		}
	}

	private unsafe void RequestFilterSync()
	{
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		NetworkManager singleton = NetworkManager.Singleton;
		if ((Object)(object)singleton == (Object)null || singleton.CustomMessagingManager == null)
		{
			return;
		}
		try
		{
			if (singleton.IsServer)
			{
				BroadcastFilter(singleton.CustomMessagingManager, null);
			}
			else if (singleton.LocalClientId != 0L)
			{
				FastBufferWriter val = default(FastBufferWriter);
				((FastBufferWriter)(ref val))..ctor(4, (Allocator)2, -1);
				try
				{
					singleton.CustomMessagingManager.SendNamedMessage("KsmPlushEnemyFilter", 0uL, val, (NetworkDelivery)2);
					return;
				}
				finally
				{
					((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
				}
			}
		}
		catch (Exception ex)
		{
			if (logVerbose)
			{
				Debug.LogWarning((object)("[KsmPlush] filter sync failed: " + ex.Message));
			}
		}
	}

	private unsafe void BroadcastFilter(CustomMessagingManager cmm, ulong? only)
	{
		//IL_004d: 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_008d: 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)
		string s = (hostFilterCsv = ((ConfigEnemyFilter != null) ? (ConfigEnemyFilter() ?? "") : ""));
		byte[] bytes = Encoding.UTF8.GetBytes(s);
		FastBufferWriter val = default(FastBufferWriter);
		((FastBufferWriter)(ref val))..ctor(bytes.Length + 4, (Allocator)2, -1);
		try
		{
			int num = bytes.Length;
			((FastBufferWriter)(ref val)).WriteValueSafe<int>(ref num, default(ForPrimitives));
			if (bytes.Length != 0)
			{
				((FastBufferWriter)(ref val)).WriteBytesSafe(bytes, -1, 0);
			}
			if (only.HasValue)
			{
				cmm.SendNamedMessage("KsmPlushEnemyFilter", only.Value, val, (NetworkDelivery)2);
			}
			else
			{
				cmm.SendNamedMessageToAll("KsmPlushEnemyFilter", val, (NetworkDelivery)2);
			}
		}
		finally
		{
			((IDisposable)(*(FastBufferWriter*)(&val))/*cast due to .constrained prefix*/).Dispose();
		}
	}

	private void OnFilterMessage(ulong senderId, FastBufferReader reader)
	{
		//IL_002e: 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)
		try
		{
			NetworkManager singleton = NetworkManager.Singleton;
			if (singleton.IsServer)
			{
				BroadcastFilter(singleton.CustomMessagingManager, null);
				return;
			}
			int num = default(int);
			((FastBufferReader)(ref reader)).ReadValueSafe<int>(ref num, default(ForPrimitives));
			if (num >= 0 && num <= 4096)
			{
				byte[] bytes = new byte[num];
				if (num > 0)
				{
					((FastBufferReader)(ref reader)).ReadBytesSafe(ref bytes, num, 0);
				}
				hostFilterCsv = ((num > 0) ? Encoding.UTF8.GetString(bytes) : "");
				filterRaw = null;
				if (logVerbose)
				{
					Debug.Log((object)("[KsmPlush] host enemy filter = '" + hostFilterCsv + "'"));
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[KsmPlush] filter message failed: " + ex.Message));
		}
	}

	private bool EnemyAllowed(EnemyAI e)
	{
		string text = ((hostFilterCsv != null) ? hostFilterCsv : ((ConfigEnemyFilter != null) ? ConfigEnemyFilter() : ""));
		if (string.IsNullOrEmpty(text) || text.Trim().Length == 0)
		{
			return true;
		}
		if (!string.Equals(text, filterRaw, StringComparison.Ordinal))
		{
			filterRaw = text;
			filterSet.Clear();
			string[] array = text.Split(new char[3] { ',', ';', '|' }, StringSplitOptions.RemoveEmptyEntries);
			for (int i = 0; i < array.Length; i++)
			{
				string text2 = array[i].Trim().ToLowerInvariant();
				if (text2.Length > 0)
				{
					filterSet.Add(text2);
				}
			}
		}
		if (filterSet.Count == 0)
		{
			return true;
		}
		string text3 = ((object)e).GetType().Name.ToLowerInvariant();
		string text4 = (((Object)(object)e.enemyType != (Object)null && !string.IsNullOrEmpty(e.enemyType.enemyName)) ? e.enemyType.enemyName.ToLowerInvariant() : "");
		string text5 = ((Object)e).name.ToLowerInvariant();
		foreach (string item in filterSet)
		{
			if (text3 == item || text4 == item)
			{
				return true;
			}
			if (item.Length >= 3 && (text3.Contains(item) || text4.Contains(item) || text5.Contains(item)))
			{
				return true;
			}
		}
		return false;
	}

	private void ApplyEnemies(Vector3 anchor)
	{
		//IL_009d: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: 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_0212: Unknown result type (might be due to invalid IL or missing references)
		//IL_0217: Unknown result type (might be due to invalid IL or missing references)
		//IL_0218: 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_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		if (!EnemyDance)
		{
			if (frozenSpeeds.Count > 0)
			{
				List<EnemyAI> list = new List<EnemyAI>(frozenSpeeds.Keys);
				for (int i = 0; i < list.Count; i++)
				{
					Unfreeze(list[i]);
				}
				frozenSpeeds.Clear();
			}
			return;
		}
		RoundManager instance = RoundManager.Instance;
		if ((Object)(object)instance == (Object)null || instance.SpawnedEnemies == null)
		{
			return;
		}
		float num = EnemyRadius();
		float num2 = num * num;
		Vector3 val2;
		for (int j = 0; j < instance.SpawnedEnemies.Count; j++)
		{
			EnemyAI val = instance.SpawnedEnemies[j];
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			val2 = ((Component)val).transform.position - anchor;
			if (!(((Vector3)(ref val2)).sqrMagnitude > num2) && EnemyAllowed(val) && (Object)(object)val.agent != (Object)null && !frozenSpeeds.ContainsKey(val))
			{
				FrozenEnemy frozenEnemy = new FrozenEnemy();
				frozenEnemy.speed = val.agent.speed;
				frozenEnemy.visual = FindVisual(((Component)val).transform);
				if ((Object)(object)frozenEnemy.visual != (Object)null)
				{
					frozenEnemy.baseScale = frozenEnemy.visual.localScale;
				}
				frozenSpeeds[val] = frozenEnemy;
				val.agent.speed = 0f;
				val.agent.isStopped = true;
				if (logVerbose)
				{
					Debug.Log((object)("[KsmPlush] enemy frozen: " + ((Object)val).name + " visual=" + (((Object)(object)frozenEnemy.visual != (Object)null) ? ((Object)frozenEnemy.visual).name : "none")));
				}
			}
		}
		toRelease.Clear();
		foreach (KeyValuePair<EnemyAI, FrozenEnemy> frozenSpeed in frozenSpeeds)
		{
			if ((Object)(object)frozenSpeed.Key == (Object)null)
			{
				toRelease.Add(frozenSpeed.Key);
				continue;
			}
			val2 = ((Component)frozenSpeed.Key).transform.position - anchor;
			if (((Vector3)(ref val2)).sqrMagnitude > num2 * 1.15f)
			{
				toRelease.Add(frozenSpeed.Key);
			}
		}
		for (int k = 0; k < toRelease.Count; k++)
		{
			Unfreeze(toRelease[k]);
		}
	}

	private void ApplyVanillaPlayers(Vector3 anchor)
	{
		//IL_004e: 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_0059: Unknown result type (might be due to invalid IL or missing references)
		StartOfRound instance = StartOfRound.Instance;
		if ((Object)(object)instance == (Object)null || instance.allPlayerScripts == null)
		{
			return;
		}
		float num = GroundRadius();
		float num2 = num * num;
		for (int i = 0; i < instance.allPlayerScripts.Length; i++)
		{
			PlayerControllerB val = instance.allPlayerScripts[i];
			if ((Object)(object)val == (Object)null || !val.isPlayerControlled)
			{
				continue;
			}
			Vector3 val2 = ((Component)val).transform.position - anchor;
			if (!(((Vector3)(ref val2)).sqrMagnitude > num2) && !((Object)(object)val.playerBodyAnimator == (Object)null))
			{
				if (!val.performingEmote || val.playerBodyAnimator.GetInteger("emoteNumber") != emoteNumber)
				{
					val.playerBodyAnimator.SetInteger("emoteNumber", emoteNumber);
					val.performingEmote = true;
				}
				if (!vanillaDancers.Contains(val))
				{
					vanillaDancers.Add(val);
				}
			}
		}
	}

	private void Unfreeze(EnemyAI e)
	{
		//IL_0067: Unknown result type (might be due to invalid IL or missing references)
		FrozenEnemy value;
		if ((Object)(object)e == (Object)null)
		{
			frozenSpeeds.Remove(e);
		}
		else if (frozenSpeeds.TryGetValue(e, out value))
		{
			if ((Object)(object)e.agent != (Object)null)
			{
				e.agent.speed = value.speed;
				e.agent.isStopped = false;
			}
			if ((Object)(object)value.visual != (Object)null)
			{
				value.visual.localScale = value.baseScale;
			}
			frozenSpeeds.Remove(e);
		}
	}

	private void ReleaseAll()
	{
		dancing = false;
		tmeSlot = int.MinValue;
		List<EnemyAI> list = new List<EnemyAI>(frozenSpeeds.Keys);
		for (int i = 0; i < list.Count; i++)
		{
			Unfreeze(list[i]);
		}
		frozenSpeeds.Clear();
		StopTme();
		for (int j = 0; j < vanillaDancers.Count; j++)
		{
			PlayerControllerB val = vanillaDancers[j];
			if (!((Object)(object)val == (Object)null))
			{
				val.performingEmote = false;
				if ((Object)(object)val.playerBodyAnimator != (Object)null)
				{
					val.playerBodyAnimator.SetInteger("emoteNumber", 0);
				}
			}
		}
		vanillaDancers.Clear();
	}

	private void InitTme()
	{
		if (tmeChecked)
		{
			return;
		}
		tmeChecked = true;
		try
		{
			Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
			for (int i = 0; i < assemblies.Length; i++)
			{
				Type type = assemblies[i].GetType("TooManyEmotes.EmoteControllerPlayer", throwOnError: false);
				if (type == null)
				{
					continue;
				}
				Type type2 = assemblies[i].GetType("TooManyEmotes.UnlockableEmote", throwOnError: false);
				Type type3 = assemblies[i].GetType("TooManyEmotes.EmotesManager", throwOnError: false);
				if (!(type2 == null) && !(type3 == null))
				{
					tmeControllerType = type;
					tmeEmoteType = type2;
					tmeLocalProp = type.GetProperty("emoteControllerLocal", BindingFlags.Static | BindingFlags.Public);
					tmePerform = type.GetMethod("PerformEmote", new Type[3]
					{
						type2,
						typeof(int),
						typeof(bool)
					});
					tmeStop = type.GetMethod("StopPerformingEmote", BindingFlags.Instance | BindingFlags.Public);
					tmeAllEmotes = type3.GetField("allUnlockableEmotes", BindingFlags.Static | BindingFlags.Public);
					tmeEmotePose = type2.GetField("isPose", BindingFlags.Instance | BindingFlags.Public);
					tmeEmoteNeedsProp = type2.GetField("requiresHeldProp", BindingFlags.Instance | BindingFlags.Public);
					tmeEmoteName = type2.GetField("emoteName", BindingFlags.Instance | BindingFlags.Public);
					tmeAvailable = tmePerform != null && tmeAllEmotes != null && tmeStop != null;
					if (logVerbose)
					{
						Debug.Log((object)("[KsmPlush] TooManyEmotes detected, available=" + tmeAvailable));
					}
				}
				return;
			}
			if (logVerbose)
			{
				Debug.Log((object)"[KsmPlush] TooManyEmotes not installed");
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[KsmPlush] TooManyEmotes probe failed: " + ex.Message));
		}
	}

	private bool TmeEnabled()
	{
		if (ConfigTooManyEmotes != null)
		{
			return ConfigTooManyEmotes();
		}
		return true;
	}

	private bool TmeActive()
	{
		InitTme();
		if (tmeAvailable)
		{
			return TmeEnabled();
		}
		return false;
	}

	private void TmeTick(Vector3 anchor)
	{
		//IL_0049: 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_0088: Unknown result type (might be due to invalid IL or missing references)
		if (!tmeAvailable)
		{
			return;
		}
		IList list = null;
		try
		{
			list = tmeAllEmotes.GetValue(null) as IList;
		}
		catch
		{
		}
		if (list == null || list.Count == 0)
		{
			return;
		}
		float num = DanceInterval();
		float num2 = Time.time;
		NetworkManager singleton = NetworkManager.Singleton;
		if ((Object)(object)singleton != (Object)null)
		{
			NetworkTime serverTime = singleton.ServerTime;
			num2 = ((NetworkTime)(ref serverTime)).TimeAsFloat;
		}
		int num3 = Mathf.FloorToInt(num2 / num);
		if (num3 != tmeSlot)
		{
			tmeSlot = num3;
			object obj2 = PickEmote(list, num3);
			if (obj2 != null)
			{
				ApplyTmeEmote(obj2, anchor);
			}
		}
	}

	private object PickEmote(IList list, int slot)
	{
		int num = (slot * 397) ^ (int)((NetworkBehaviour)this).NetworkObjectId;
		int num2 = ((num ^ (num >> 13)) & 0x7FFFFFFF) % list.Count;
		for (int i = 0; i < list.Count; i++)
		{
			object obj = list[(num2 + i) % list.Count];
			if (obj != null && (!(tmeEmotePose != null) || !(tmeEmotePose.GetValue(obj) is bool) || !(bool)tmeEmotePose.GetValue(obj)) && (!(tmeEmoteNeedsProp != null) || !(tmeEmoteNeedsProp.GetValue(obj) is bool) || !(bool)tmeEmoteNeedsProp.GetValue(obj)))
			{
				return obj;
			}
		}
		return null;
	}

	private void ApplyTmeEmote(object emote, Vector3 anchor)
	{
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_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)
		StartOfRound instance = StartOfRound.Instance;
		if ((Object)(object)instance == (Object)null)
		{
			return;
		}
		PlayerControllerB localPlayerController = instance.localPlayerController;
		if ((Object)(object)localPlayerController == (Object)null || !localPlayerController.isPlayerControlled)
		{
			return;
		}
		float num = GroundRadius();
		Vector3 val = ((Component)localPlayerController).transform.position - anchor;
		if (((Vector3)(ref val)).sqrMagnitude > num * num)
		{
			return;
		}
		Component val2 = ((Component)localPlayerController).GetComponent(tmeControllerType) ?? ((Component)localPlayerController).GetComponentInChildren(tmeControllerType, true);
		bool flag = false;
		if ((Object)(object)val2 != (Object)null)
		{
			try
			{
				tmeStop.Invoke(val2, null);
				object obj = tmePerform.Invoke(val2, new object[3] { emote, -1, false });
				flag = obj is bool && (bool)obj;
			}
			catch (Exception ex)
			{
				if (logVerbose)
				{
					Debug.LogWarning((object)("[KsmPlush] TME apply failed: " + ex.Message));
				}
			}
			if (flag && !tmeDriven.Contains(val2))
			{
				tmeDriven.Add(val2);
			}
		}
		if (flag)
		{
			lastTmeName = ((tmeEmoteName != null) ? ((tmeEmoteName.GetValue(emote) as string) ?? "") : "");
			if (logVerbose)
			{
				Debug.Log((object)("[KsmPlush] TME emote -> " + lastTmeName));
			}
		}
		else if ((Object)(object)localPlayerController.playerBodyAnimator != (Object)null)
		{
			localPlayerController.playerBodyAnimator.SetInteger("emoteNumber", emoteNumber);
			localPlayerController.performingEmote = true;
			if (!vanillaDancers.Contains(localPlayerController))
			{
				vanillaDancers.Add(localPlayerController);
			}
		}
	}

	private void StopTme()
	{
		if (tmeDriven.Count == 0)
		{
			return;
		}
		for (int i = 0; i < tmeDriven.Count; i++)
		{
			if (tmeDriven[i] == null)
			{
				continue;
			}
			try
			{
				tmeStop.Invoke(tmeDriven[i], null);
			}
			catch (Exception ex)
			{
				if (logVerbose)
				{
					Debug.LogWarning((object)("[KsmPlush] TME stop failed: " + ex.Message));
				}
			}
		}
		tmeDriven.Clear();
	}
}
public class PlushUI : MonoBehaviour
{
	public static bool Visible;

	public static float Volume = 0.9f;

	public static bool Mute;

	public static Action<float> OnVolumeChanged;

	public static Action<bool> OnMuteChanged;

	public static Action OnCommit;

	private static float _savedVolume = -1f;

	private static Texture2D _bg;

	private static GUIStyle _label;

	private static GUIStyle _title;

	private void Update()
	{
		try
		{
			Keyboard current = Keyboard.current;
			if (current != null && ((ButtonControl)current.f10Key).wasPressedThisFrame)
			{
				SetVisible(!Visible);
			}
			if (Visible && Mouse.current != null && Mouse.current.leftButton.wasReleasedThisFrame)
			{
				Commit();
			}
		}
		catch
		{
		}
	}

	private static void Commit()
	{
		if (Mathf.Abs(_savedVolume - Volume) <= 0.001f)
		{
			return;
		}
		_savedVolume = Volume;
		try
		{
			if (OnCommit != null)
			{
				OnCommit();
			}
		}
		catch
		{
		}
	}

	private static void SetVisible(bool on)
	{
		if (Visible && !on)
		{
			Commit();
		}
		Visible = on;
		try
		{
			Cursor.visible = on || Cursor.visible;
			Cursor.lockState = (CursorLockMode)(!on);
		}
		catch
		{
		}
	}

	private void OnGUI()
	{
		if (!Visible)
		{
			return;
		}
		try
		{
			Draw();
		}
		catch
		{
		}
	}

	private void Draw()
	{
		//IL_0020: 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_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f1: Unknown result type (might be due to invalid IL or missing references)
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
		EnsureStyles();
		Rect val = default(Rect);
		((Rect)(ref val))..ctor(40f, 40f, 340f, 170f);
		GUI.DrawTexture(val, (Texture)(object)_bg);
		GUI.Label(new Rect(((Rect)(ref val)).x + 16f, ((Rect)(ref val)).y + 10f, ((Rect)(ref val)).width - 32f, 28f), "Ksm Plush  音乐设置 (F10)", _title);
		GUI.Label(new Rect(((Rect)(ref val)).x + 16f, ((Rect)(ref val)).y + 52f, 90f, 24f), "音量 " + Mathf.RoundToInt(Volume * 100f) + "%", _label);
		float num = GUI.HorizontalSlider(new Rect(((Rect)(ref val)).x + 110f, ((Rect)(ref val)).y + 60f, ((Rect)(ref val)).width - 140f, 20f), Volume, 0f, 1f);
		if (Mathf.Abs(num - Volume) > 0.001f)
		{
			Volume = num;
			if (OnVolumeChanged != null)
			{
				OnVolumeChanged(Volume);
			}
		}
		bool flag = GUI.Toggle(new Rect(((Rect)(ref val)).x + 16f, ((Rect)(ref val)).y + 96f, ((Rect)(ref val)).width - 32f, 24f), Mute, " 静音 (mute)");
		if (flag != Mute)
		{
			Mute = flag;
			if (OnMuteChanged != null)
			{
				OnMuteChanged(Mute);
			}
		}
		GUI.Label(new Rect(((Rect)(ref val)).x + 16f, ((Rect)(ref val)).y + 126f, ((Rect)(ref val)).width - 32f, 34f), "怪物白名单请改 BepInEx/config/meow.KsmPlushItem.cfg", _label);
	}

	private static void EnsureStyles()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0019: Expected O, but got Unknown
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		//IL_0059: Unknown result type (might be due to invalid IL or missing references)
		//IL_0063: Expected O, but got Unknown
		//IL_007c: 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_00a1: Expected O, but got Unknown
		//IL_00c2: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)_bg == (Object)null)
		{
			_bg = new Texture2D(1, 1);
			_bg.SetPixel(0, 0, new Color(0.32f, 0.05f, 0.05f, 0.92f));
			_bg.Apply();
		}
		if (_label == null)
		{
			_label = new GUIStyle(GUI.skin.label);
			_label.normal.textColor = new Color(1f, 0.92f, 0.92f);
			_label.fontSize = 15;
			_title = new GUIStyle(_label);
			_title.fontSize = 18;
			_title.fontStyle = (FontStyle)1;
			_title.normal.textColor = Color.white;
		}
	}
}
public static class VisualFix
{
	public static Func<bool> ConfigUnlit;

	public static Func<int> ConfigDoubleSidedOverride;

	public static Func<float> ConfigSmoothness;

	public static Func<float> ConfigEmission;

	public static Action<string> Log;

	private static readonly int BaseMapId = Shader.PropertyToID("_BaseColorMap");

	private static readonly int UnlitMapId = Shader.PropertyToID("_UnlitColorMap");

	private static readonly int BaseColorId = Shader.PropertyToID("_BaseColor");

	private static readonly int UnlitColorId = Shader.PropertyToID("_UnlitColor");

	private static readonly int SmoothnessId = Shader.PropertyToID("_Smoothness");

	private static readonly int MetallicId = Shader.PropertyToID("_Metallic");

	private static readonly int EmissiveColorId = Shader.PropertyToID("_EmissiveColor");

	private static readonly int DoubleSidedId = Shader.PropertyToID("_DoubleSidedEnable");

	private static readonly int CullModeId = Shader.PropertyToID("_CullMode");

	private static readonly int CullModeFwdId = Shader.PropertyToID("_CullModeForward");

	private static bool dumped;

	private static void Say(string msg)
	{
		if (Log != null)
		{
			Log("[KsmPlush][vis] " + msg);
		}
	}

	public static void Apply(GameObject root, string when)
	{
		//IL_00da: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e1: Expected O, but got Unknown
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_01df: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c2: Unknown result type (might be due to invalid IL or missing references)
		//IL_03c7: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)root == (Object)null)
		{
			return;
		}
		bool flag = ConfigUnlit != null && ConfigUnlit();
		int num = ((ConfigDoubleSidedOverride != null) ? ConfigDoubleSidedOverride() : (-1));
		float num2 = ((ConfigSmoothness != null) ? ConfigSmoothness() : (-1f));
		float num3 = ((ConfigEmission != null) ? ConfigEmission() : (-1f));
		if (!flag && num < 0 && num2 < 0f && num3 < 0f)
		{
			return;
		}
		Shader val = (flag ? Shader.Find("HDRP/Unlit") : null);
		if (flag && (Object)(object)val == (Object)null)
		{
			Say("HDRP/Unlit shader not found, staying lit");
		}
		Renderer[] componentsInChildren = root.GetComponentsInChildren<Renderer>(true);
		int num4 = 0;
		foreach (Renderer val2 in componentsInChildren)
		{
			Material sharedMaterial = val2.sharedMaterial;
			if ((Object)(object)sharedMaterial == (Object)null)
			{
				continue;
			}
			Material val3 = new Material(sharedMaterial);
			((Object)val3).name = ((Object)sharedMaterial).name + "_Runtime";
			Texture val4 = null;
			if (sharedMaterial.HasProperty(BaseMapId))
			{
				val4 = sharedMaterial.GetTexture(BaseMapId);
			}
			if ((Object)(object)val4 == (Object)null && sharedMaterial.HasProperty(UnlitMapId))
			{
				val4 = sharedMaterial.GetTexture(UnlitMapId);
			}
			if ((Object)(object)val != (Object)null)
			{
				val3.shader = val;
				if ((Object)(object)val4 != (Object)null)
				{
					val3.SetTexture(UnlitMapId, val4);
				}
				val3.SetColor(UnlitColorId, Color.white);
				val3.DisableKeyword("_NORMALMAP");
				val3.DisableKeyword("_NORMALMAP_TANGENT_SPACE");
			}
			else
			{
				val3.SetFloat(MetallicId, 0f);
				if (num2 >= 0f)
				{
					val3.SetFloat(SmoothnessId, num2);
				}
				if (num3 >= 0f && val3.HasProperty(EmissiveColorId))
				{
					val3.SetColor(EmissiveColorId, new Color(num3, num3, num3, 1f));
				}
			}
			if (num >= 0)
			{
				val3.SetFloat(DoubleSidedId, (num > 0) ? 1f : 0f);
				val3.SetFloat(CullModeId, (num > 0) ? 0f : 2f);
				val3.SetFloat(CullModeFwdId, (num > 0) ? 0f : 2f);
			}
			val2.sharedMaterial = val3;
			num4++;
			if (!dumped)
			{
				dumped = true;
				string text = "";
				string[] shaderKeywords = val3.shaderKeywords;
				for (int j = 0; j < shaderKeywords.Length; j++)
				{
					text = text + ((j == 0) ? "" : ",") + shaderKeywords[j];
				}
				Texture2D val5 = (Texture2D)(object)((val4 is Texture2D) ? val4 : null);
				Say("at=" + when + " renderer=" + ((Object)val2).name + " from=" + ((Object)sharedMaterial.shader).name + " to=" + ((Object)val3.shader).name + " kw=" + text + " dblOverride=" + num + " smooth=" + ((num2 < 0f) ? "keep" : num2.ToString()) + " emis=" + num3 + " tex=" + (((Object)(object)val5 == (Object)null) ? "null" : (((Object)val5).name + " " + ((Texture)val5).width + "x" + ((Texture)val5).height + " fmt=" + ((object)val5.format/*cast due to .constrained prefix*/).ToString() + " mips=" + ((Texture)val5).mipmapCount)) + " queue=" + val3.renderQueue);
			}
		}
		if (!dumped)
		{
			Say("at=" + when + " no renderer with a material under " + ((Object)root).name + " (seen=" + componentsInChildren.Length + ")");
		}
		else if (when == "start")
		{
			Say("patched " + num4 + " renderer(s)");
		}
	}
}

BepInEx/plugins/KsmPlush/KsmPlushItem.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using KsmPlush;
using LethalLib.Modules;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace KsmPlushItem;

[BepInPlugin("meow.KsmPlushItem", "KsmPlush Toy", "1.4.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public const string GUID = "meow.KsmPlushItem";

	internal static ManualLogSource Log;

	private static AssetBundle bundle;

	internal static ConfigEntry<float> CfgDanceRadius;

	internal static ConfigEntry<float> CfgHeldDanceRadius;

	internal static ConfigEntry<float> ConfigEnemyRadiusEntry;

	internal static ConfigEntry<float> CfgEnemySpin;

	internal static ConfigEntry<bool> CfgEnemyQBounce;

	internal static ConfigEntry<bool> CfgTmeEnabled;

	internal static ConfigEntry<float> CfgTmeInterval;

	internal static ConfigEntry<bool> CfgVerbose;

	internal static ConfigEntry<float> CfgVolume;

	internal static ConfigEntry<bool> CfgMute;

	internal static ConfigEntry<string> CfgEnemyFilter;

	internal static ConfigEntry<bool> CfgEnableUI;

	internal static ConfigEntry<bool> CfgHostSync;

	internal static ConfigEntry<bool> CfgForceUnlit;

	internal static ConfigEntry<int> CfgDoubleSided;

	internal static ConfigEntry<float> CfgSmallWeight;

	internal static ConfigEntry<float> CfgBigWeight;

	internal static ConfigEntry<float> CfgSmoothness;

	internal static ConfigEntry<float> CfgEmission;

	internal static ConfigEntry<int> CfgBigRarity;

	internal static ConfigEntry<string> CfgNextKey;

	internal static ConfigEntry<bool> CfgEnemyDance;

	internal static ConfigEntry<float> CfgBigRadius;

	private static string SafeKey(string key)
	{
		char[] array = new char[8] { '=', '\n', '\t', '\\', '"', '\'', '[', ']' };
		string text = key;
		for (int i = 0; i < array.Length; i++)
		{
			text = text.Replace(array[i].ToString(), string.Empty);
		}
		return text.Trim();
	}

	internal static float LbToWeight(float lb)
	{
		return Mathf.Clamp(1f + Mathf.Clamp(lb, 0f, 315f) / 105f, 1.001f, 3.999f);
	}

	private void Awake()
	{
		//IL_01a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b1: Expected O, but got Unknown
		Log = ((BaseUnityPlugin)this).Logger;
		CfgDanceRadius = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Singing"), SafeKey("Dance radius"), 15f, "Radius in metres when the plush lies on the floor: players inside it dance the vanilla emote.");
		CfgHeldDanceRadius = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Singing"), SafeKey("Held dance radius"), 6f, "Radius in metres around the player holding the plush: everyone inside dances the same TooManyEmotes emote.");
		ConfigEnemyRadiusEntry = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Singing"), SafeKey("Enemy control radius"), 15f, "Radius in metres where enemies get frozen and spun while the plush sings.");
		CfgEnemyQBounce = ((BaseUnityPlugin)this).Config.Bind<bool>(SafeKey("Singing"), SafeKey("Enemy q-bounce squash"), true, "Give controlled enemies the same squash/stretch wobble as the plush.");
		CfgEnemySpin = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Singing"), SafeKey("Enemy spin degrees per second"), 392.727f, "How fast controlled enemies rotate, in degrees per second (392.7 = one q-bounce turn per 0.92s, negative = other direction).");
		CfgTmeEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(SafeKey("TooManyEmotes"), SafeKey("Enable random dances"), false, "When the plush sings, randomly trigger TooManyEmotes emotes on the local player.");
		CfgTmeInterval = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("TooManyEmotes"), SafeKey("Random dance interval"), 6f, "Average seconds between random TooManyEmotes dances (actual value is 0.75x - 1.25x).");
		CfgVerbose = ((BaseUnityPlugin)this).Config.Bind<bool>(SafeKey("Debug"), SafeKey("Verbose logging"), false, "Log material/renderer and dance diagnostics to the BepInEx console.");
		CfgVolume = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Audio"), SafeKey("Volume"), 0.9f, new ConfigDescription("Music volume for this client (0 = silent, 1 = full). Also editable in game with F10.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		CfgMute = ((BaseUnityPlugin)this).Config.Bind<bool>(SafeKey("Audio"), SafeKey("Muted"), false, "Mute the plush music for this client. Also editable in game with F10.");
		CfgEnableUI = ((BaseUnityPlugin)this).Config.Bind<bool>(SafeKey("Debug"), SafeKey("Enable F10 volume panel"), false, "Off by default: volume and mute live in this config file only. Set true to bring back the F10 panel.");
		CfgHostSync = ((BaseUnityPlugin)this).Config.Bind<bool>(SafeKey("Debug"), SafeKey("Sync enemy filter from host"), false, "Off by default. Set true if you want clients to adopt the host's enemy whitelist (uses a custom network message).");
		CfgEnemyFilter = ((BaseUnityPlugin)this).Config.Bind<string>(SafeKey("Singing"), SafeKey("Enemies that get controlled (comma separated, empty means all)"), "", "Enemy type names, e.g. 'CentipedeAI, HoarderBugAI, MouthDogAI'. Empty means every enemy, including modded ones. The host's list is used for everyone.");
		PlushBehaviour.ConfigDanceRadius = () => CfgDanceRadius.Value;
		PlushBehaviour.ConfigHeldDanceRadius = () => CfgHeldDanceRadius.Value;
		PlushBehaviour.ConfigEnemyRadius = () => ConfigEnemyRadiusEntry.Value;
		PlushBehaviour.ConfigEnemySpinSpeed = () => CfgEnemySpin.Value;
		PlushBehaviour.ConfigEnemyQBounce = () => CfgEnemyQBounce.Value;
		PlushBehaviour.ConfigTooManyEmotes = () => CfgTmeEnabled.Value;
		PlushBehaviour.ConfigDanceChangeInterval = () => CfgTmeInterval.Value;
		PlushBehaviour.logVerbose = CfgVerbose.Value;
		PlushBehaviour.ConfigVolume = () => PlushUI.Volume;
		PlushBehaviour.ConfigMute = () => PlushUI.Mute;
		PlushBehaviour.ConfigEnemyFilter = () => CfgEnemyFilter.Value;
		PlushBehaviour.ConfigEnableUI = () => CfgEnableUI.Value;
		PlushBehaviour.ConfigHostSync = () => CfgHostSync.Value;
		CfgForceUnlit = ((BaseUnityPlugin)this).Config.Bind<bool>(SafeKey("Visual"), SafeKey("Force unlit shader"), false, "Render the plush with HDRP/Unlit instead of HDRP/Lit. Use this to find out whether the hard white polygons come from lighting or from the texture.");
		CfgDoubleSided = ((BaseUnityPlugin)this).Config.Bind<int>(SafeKey("Visual"), SafeKey("Double sided override (-1 keeps bundle)"), -1, "0 = single sided, 1 = draw both faces, -1 = keep what the bundle was built with (currently double sided). Runtime overrides force a new shader variant and cause a short hitch when the item spawns.");
		CfgSmoothness = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Visual"), SafeKey("Smoothness override (-1 keeps bundle)"), -1f, "Overrides _Smoothness at runtime. 0 kills the specular highlight that shows up as flat white polygons in bright rooms.");
		CfgEmission = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Visual"), SafeKey("Emission override (-1 keeps bundle)"), -1f, "Overrides _EmissiveColor at runtime (0 = no glow, 0.3 = soft self-lit look).");
		VisualFix.ConfigUnlit = () => CfgForceUnlit.Value;
		VisualFix.ConfigDoubleSidedOverride = () => CfgDoubleSided.Value;
		VisualFix.ConfigSmoothness = () => CfgSmoothness.Value;
		VisualFix.ConfigEmission = () => CfgEmission.Value;
		VisualFix.Log = delegate(string msg)
		{
			Log.LogInfo((object)msg);
		};
		PlushBehaviour.ConfigNextKey = () => CfgNextKey.Value;
		PlushBehaviour.ConfigEnemyDance = () => CfgEnemyDance.Value;
		CfgSmallWeight = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Items"), SafeKey("Small plush weight (lb)"), 1f, "How many pounds the HUD should show for the small plush (default 1). The game scales weight internally, this value is already converted.");
		CfgBigWeight = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Items"), SafeKey("Big plush weight (lb)"), 10f, "How many pounds the HUD should show for the big plush (default 10). The game scales weight internally, this value is already converted. LethalLib clamps scrap weight on registration, so it is re-applied afterwards.");
		CfgBigRadius = ((BaseUnityPlugin)this).Config.Bind<float>(SafeKey("Singing"), SafeKey("Big plush radius"), 20f, "Song radius in metres for the big plush (players dance / monsters get frozen inside it). The small plush uses Dance radius and Enemy control radius.");
		CfgEnemyDance = ((BaseUnityPlugin)this).Config.Bind<bool>(SafeKey("Singing"), SafeKey("Monsters join the dance"), true, "Whether enemies inside the radius freeze and spin along with the music. Turn it off if you only want the crew dancing.");
		CfgNextKey = ((BaseUnityPlugin)this).Config.Bind<string>(SafeKey("Keys"), SafeKey("Next track key"), "F", "Key that plays the next song on the big plush (a Unity Input System key name: F, T, MouseMiddle ...). Left click is unchanged.");
		CfgBigRarity = ((BaseUnityPlugin)this).Config.Bind<int>(SafeKey("Spawning"), SafeKey("Big plush spawn rarity"), 5, "How often the big plush shows up as scrap: an integer weight relative to every other scrap item on the same level. Bigger = more common; 0 turns it off. Only the host's value matters.");
		PlushUI.Volume = CfgVolume.Value;
		PlushUI.Mute = CfgMute.Value;
		PlushUI.OnVolumeChanged = delegate
		{
		};
		PlushUI.OnMuteChanged = delegate(bool m)
		{
			CfgMute.Value = m;
		};
		PlushUI.OnCommit = delegate
		{
			if (Math.Abs(CfgVolume.Value - PlushUI.Volume) > 0.001f)
			{
				CfgVolume.Value = PlushUI.Volume;
			}
		};
		CfgVolume.SettingChanged += delegate
		{
			PlushUI.Volume = CfgVolume.Value;
		};
		CfgMute.SettingChanged += delegate
		{
			PlushUI.Mute = CfgMute.Value;
		};
		if (CfgEnableUI.Value)
		{
			((Component)this).gameObject.AddComponent<PlushUI>();
		}
		else
		{
			Log.LogInfo((object)"[KsmPlush] F10 panel disabled by config");
		}
		string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		bundle = AssetBundle.LoadFromFile(Path.Combine(directoryName, "ksmplush"));
		if ((Object)(object)bundle == (Object)null)
		{
			Log.LogError((object)("[KsmPlush] could not load bundle from " + directoryName));
			return;
		}
		GameObject val = bundle.LoadAsset<GameObject>("KsmPlushToy");
		if ((Object)(object)val == (Object)null)
		{
			Log.LogError((object)"[KsmPlush] prefab 'KsmPlushToy' missing in bundle");
			return;
		}
		AudioClip[] songs = (AudioClip[])(object)new AudioClip[1] { bundle.LoadAsset<AudioClip>("song") };
		Item val2 = ScriptableObject.CreateInstance<Item>();
		PlushBehaviour component = BuildPrefab(val, val2, "KsmPlush", "Ksm Plush", songs, 0f, "Ksm Plush", 1f, isScrap: false, 120, 300, 40, 0.55f, "song", bundle, "KsmPlushIcon", "左键 播放/暂停").GetComponent<PlushBehaviour>();
		if ((Object)(object)component != (Object)null)
		{
			component.weightOverride = LbToWeight(CfgSmallWeight.Value);
		}
		Items.RegisterShopItem(val2, 665);
		val2.weight = LbToWeight(CfgSmallWeight.Value);
		Log.LogInfo((object)("[KsmPlush] registered shop item '" + val2.itemName + "' price=665 id=" + val2.itemId + " weight=" + val2.weight));
		RegisterBigToy(directoryName);
	}

	private static void RegisterBigToy(string dir)
	{
		string text = Path.Combine(dir, "ksmbig");
		if (!File.Exists(text))
		{
			Log.LogWarning((object)"[KsmPlush] ksmbig missing, big toy not registered");
			return;
		}
		AssetBundle val = AssetBundle.LoadFromFile(text);
		if ((Object)(object)val == (Object)null)
		{
			Log.LogError((object)"[KsmPlush] could not load ksmbig");
			return;
		}
		GameObject val2 = val.LoadAsset<GameObject>("KsmPlushBigToy");
		if ((Object)(object)val2 == (Object)null)
		{
			Log.LogError((object)"[KsmPlush] prefab 'KsmPlushBigToy' missing in ksmbig");
			return;
		}
		AudioClip[] array = (AudioClip[])(object)new AudioClip[7];
		int num = 0;
		for (int i = 0; i < 7; i++)
		{
			array[i] = val.LoadAsset<AudioClip>("song" + (i + 1));
			if ((Object)(object)array[i] != (Object)null)
			{
				num++;
			}
		}
		Log.LogInfo((object)("[KsmPlush] big toy songs loaded=" + num + "/7"));
		Item val3 = ScriptableObject.CreateInstance<Item>();
		PlushBehaviour component = BuildPrefab(val2, val3, "KsmPlushBig", "Ksm Plush (Big)", array, 20f, "Ksm Plush (Big)", 10f, isScrap: true, 200, 400, 300, 1.1f, "song1", val, "KsmBigIcon", "左键 播放/暂停").GetComponent<PlushBehaviour>();
		if ((Object)(object)component != (Object)null)
		{
			component.weightOverride = LbToWeight(CfgBigWeight.Value);
			component.radiusOverride = Mathf.Clamp(CfgBigRadius.Value, 1f, 100f);
		}
		Items.RegisterScrap(val3, CfgBigRarity.Value, (LevelTypes)(-1));
		val3.weight = LbToWeight(CfgBigWeight.Value);
		Log.LogInfo((object)("[KsmPlush] registered scrap '" + val3.itemName + "' rarity=" + CfgBigRarity.Value + " id=" + val3.itemId + " weight=" + val3.weight));
	}

	private static GameObject BuildPrefab(GameObject modelPrefab, Item item, string idSuffix, string scanHeader, AudioClip[] songs, float radius, string itemName, float weight, bool isScrap, int minValue, int maxValue, int creditsWorth, float fallbackHeight, string firstClipName, AssetBundle iconBundle, string iconName, string toolTip)
	{
		//IL_0065: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_017f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_0195: Unknown result type (might be due to invalid IL or missing references)
		//IL_019a: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_01b5: Unknown result type (might be due to invalid IL or missing references)
		//IL_02fe: Unknown result type (might be due to invalid IL or missing references)
		//IL_0305: Expected O, but got Unknown
		//IL_033b: Unknown result type (might be due to invalid IL or missing references)
		//IL_034e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = NetworkPrefabs.CreateNetworkPrefab("meow.KsmPlushItem." + idSuffix);
		Object.DontDestroyOnLoad((Object)(object)((Component)val.transform.root).gameObject);
		val.tag = "PhysicsProp";
		int num = LayerMask.NameToLayer("Props");
		if (num >= 0)
		{
			val.layer = num;
		}
		GameObject val2 = Object.Instantiate<GameObject>(modelPrefab, val.transform);
		((Object)val2).name = "Model";
		val2.transform.localPosition = Vector3.zero;
		val2.transform.localRotation = Quaternion.identity;
		val2.transform.localScale = Vector3.one;
		AudioSource[] componentsInChildren = val2.GetComponentsInChildren<AudioSource>(true);
		for (int i = 0; i < componentsInChildren.Length; i++)
		{
			Object.DestroyImmediate((Object)(object)componentsInChildren[i]);
		}
		Rigidbody[] componentsInChildren2 = val2.GetComponentsInChildren<Rigidbody>(true);
		for (int j = 0; j < componentsInChildren2.Length; j++)
		{
			Object.DestroyImmediate((Object)(object)componentsInChildren2[j]);
		}
		MeshRenderer[] componentsInChildren3 = val2.GetComponentsInChildren<MeshRenderer>(true);
		for (int k = 0; k < componentsInChildren3.Length; k++)
		{
			((Component)componentsInChildren3[k]).gameObject.layer = val.layer;
		}
		BoxCollider component = val2.GetComponent<BoxCollider>();
		BoxCollider val3 = val.AddComponent<BoxCollider>();
		if ((Object)(object)component != (Object)null)
		{
			val3.center = component.center;
			val3.size = component.size;
			Object.DestroyImmediate((Object)(object)component);
			Collider[] componentsInChildren4 = val2.GetComponentsInChildren<Collider>(true);
			for (int l = 0; l < componentsInChildren4.Length; l++)
			{
				Object.DestroyImmediate((Object)(object)componentsInChildren4[l]);
			}
		}
		else
		{
			val3.size = new Vector3(0.45f, 0.55f, 0.42f);
		}
		Log.LogInfo((object)("[KsmPlush] collider size=" + ((object)val3.size/*cast due to .constrained prefix*/).ToString() + " center=" + ((object)val3.center/*cast due to .constrained prefix*/).ToString()));
		Rigidbody val4 = val.AddComponent<Rigidbody>();
		val4.isKinematic = true;
		val4.useGravity = false;
		val4.mass = 1.5f;
		AudioSource val5 = val.AddComponent<AudioSource>();
		val5.playOnAwake = false;
		val5.loop = true;
		val5.spatialBlend = 1f;
		val5.rolloffMode = (AudioRolloffMode)1;
		val5.minDistance = 2f;
		val5.maxDistance = 30f;
		val5.dopplerLevel = 0f;
		val5.volume = 0.9f;
		val5.clip = ((songs != null && songs.Length != 0) ? songs[0] : null);
		PlushBehaviour val6 = val.AddComponent<PlushBehaviour>();
		((GrabbableObject)val6).itemProperties = item;
		((GrabbableObject)val6).grabbable = true;
		((GrabbableObject)val6).grabbableToEnemies = true;
		((GrabbableObject)val6).propBody = val4;
		((GrabbableObject)val6).propColliders = (Collider[])(object)new Collider[1] { (Collider)val3 };
		((GrabbableObject)val6).mainObjectRenderer = ((componentsInChildren3.Length != 0) ? componentsInChildren3[0] : null);
		val6.musicSource = val5;
		val6.model = val2.transform;
		((GrabbableObject)val6).customGrabTooltip = ((songs != null && songs.Length > 1) ? "左键 下一首" : "左键 唱歌/停止");
		val6.playlist = songs;
		val6.radiusOverride = radius;
		GameObject val7 = new GameObject("ScanNode");
		val7.transform.SetParent(val.transform, false);
		int num2 = LayerMask.NameToLayer("ScanNode");
		if (num2 >= 0)
		{
			val7.layer = num2;
		}
		val7.transform.localPosition = val3.center;
		val7.AddComponent<BoxCollider>().size = val3.size;
		ScanNodeProperties obj = val7.AddComponent<ScanNodeProperties>();
		obj.headerText = scanHeader;
		obj.subText = "Value: $0";
		obj.nodeType = 2;
		obj.maxRange = 13;
		obj.minRange = 1;
		obj.requiresLineOfSight = true;
		FillItem(item, val, val3, componentsInChildren3, itemName, weight, isScrap, minValue, maxValue, creditsWorth, iconBundle, iconName, toolTip);
		try
		{
			Utilities.FixMixerGroups(val);
		}
		catch (Exception ex)
		{
			Log.LogWarning((object)("[KsmPlush] mixer fix skipped: " + ex.Message));
		}
		return val;
	}

	private static void FillItem(Item item, GameObject prefab, BoxCollider col, MeshRenderer[] renderers, string itemName, float weight, bool isScrap, int minValue, int maxValue, int creditsWorth, AssetBundle iconBundle, string iconName, string toolTip)
	{
		//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_00f9: 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_0113: 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)
		//IL_011f: Unknown result type (might be due to invalid IL or missing references)
		AudioClip val = MakeSound("KsmPlushClink", 1500f);
		((Object)item).name = (isScrap ? "KsmPlushBigItem" : "KsmPlushItem");
		item.itemName = itemName;
		item.itemId = (isScrap ? 5872 : 5871);
		item.isScrap = isScrap;
		item.minValue = minValue;
		item.maxValue = maxValue;
		item.creditsWorth = creditsWorth;
		item.weight = LbToWeight(weight);
		item.syncUseFunction = true;
		item.holdButtonUse = false;
		item.requiresBattery = false;
		item.canBeGrabbedBeforeGameStart = true;
		item.isConductiveMetal = false;
		item.spawnPrefab = prefab;
		item.spawnPositionTypes = new List<ItemGroup>();
		item.toolTips = new string[1] { toolTip };
		item.meshVariants = Array.Empty<Mesh>();
		item.materialVariants = Array.Empty<Material>();
		item.clinkAudios = Array.Empty<AudioClip>();
		item.grabSFX = val;
		item.dropSFX = val;
		item.pocketSFX = val;
		item.restingRotation = Vector3.zero;
		item.rotationOffset = Vector3.zero;
		item.positionOffset = new Vector3(0f, 0.12f, 0f);
		item.verticalOffset = col.size.y * 0.5f;
		item.itemIcon = BuildIcon(iconBundle, iconName);
		if (renderers.Length == 0)
		{
			Log.LogWarning((object)"[KsmPlush] no renderer for mainObjectRenderer");
		}
	}

	private static Sprite BuildIcon(AssetBundle src, string iconName)
	{
		//IL_004c: 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)
		if ((Object)(object)src == (Object)null)
		{
			return null;
		}
		Texture2D val = src.LoadAsset<Texture2D>(iconName);
		if ((Object)(object)val == (Object)null)
		{
			val = src.LoadAsset<Texture2D>("KsmPlushTex");
		}
		if ((Object)(object)val == (Object)null)
		{
			return null;
		}
		return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
	}

	private static AudioClip MakeSound(string name, float frequency)
	{
		float[] array = new float[2205];
		for (int i = 0; i < array.Length; i++)
		{
			float num = (float)i / 22050f;
			array[i] = 0.2f * (float)(Math.Sin(Math.PI * 2.0 * (double)frequency * (double)num) * Math.Exp((0f - num) * 65f));
		}
		AudioClip obj = AudioClip.Create(name, array.Length, 1, 22050, false);
		obj.SetData(array, 0);
		return obj;
	}
}