Decompiled source of WitnessCreator v1.0.4

BepInEx/plugins/Dorfistain-WitnessCreator.dll

Decompiled 7 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using HarmonyLib;
using Mirror;
using SFB;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Dorfistain-WitnessCreator")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Dorfistain-WitnessCreator")]
[assembly: AssemblyTitle("Dorfistain-WitnessCreator")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public struct WitnessUploadMsg : NetworkMessage
{
	public bool isProc;

	public string witnessName;

	public byte[] pngBytes;
}
public struct WitnessOverrideMsg : NetworkMessage
{
	public bool isProc;

	public string witnessName;

	public byte[] pngBytes;
}
internal static class WitnessOverrides
{
	public static string ProcName;

	public static string DefName;

	public static Texture2D ProcTex;

	public static Texture2D DefTex;

	public static void Clear()
	{
		ProcName = (DefName = null);
		ProcTex = (DefTex = null);
	}

	public static string Name(ERole r)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Invalid comparison between Unknown and I4
		if ((int)r != 1)
		{
			return DefName;
		}
		return ProcName;
	}

	public static Texture2D Tex(ERole r)
	{
		//IL_0000: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Invalid comparison between Unknown and I4
		if ((int)r != 1)
		{
			return DefTex;
		}
		return ProcTex;
	}

	public static void Set(bool isProc, string name, Texture2D tex)
	{
		if (isProc)
		{
			ProcName = name;
			ProcTex = tex;
		}
		else
		{
			DefName = name;
			DefTex = tex;
		}
	}
}
internal static class WitnessReadWrite
{
	public static void WriteUpload(NetworkWriter w, WitnessUploadMsg m)
	{
		NetworkWriterExtensions.WriteBool(w, m.isProc);
		NetworkWriterExtensions.WriteString(w, m.witnessName);
		NetworkWriterExtensions.WriteBytesAndSize(w, m.pngBytes ?? new byte[0]);
	}

	public static WitnessUploadMsg ReadUpload(NetworkReader r)
	{
		WitnessUploadMsg result = default(WitnessUploadMsg);
		result.isProc = NetworkReaderExtensions.ReadBool(r);
		result.witnessName = NetworkReaderExtensions.ReadString(r);
		result.pngBytes = NetworkReaderExtensions.ReadBytesAndSize(r) ?? new byte[0];
		return result;
	}

	public static void WriteOverride(NetworkWriter w, WitnessOverrideMsg m)
	{
		NetworkWriterExtensions.WriteBool(w, m.isProc);
		NetworkWriterExtensions.WriteString(w, m.witnessName);
		NetworkWriterExtensions.WriteBytesAndSize(w, m.pngBytes ?? new byte[0]);
	}

	public static WitnessOverrideMsg ReadOverride(NetworkReader r)
	{
		WitnessOverrideMsg result = default(WitnessOverrideMsg);
		result.isProc = NetworkReaderExtensions.ReadBool(r);
		result.witnessName = NetworkReaderExtensions.ReadString(r);
		result.pngBytes = NetworkReaderExtensions.ReadBytesAndSize(r) ?? new byte[0];
		return result;
	}
}
[BepInPlugin("Dorfistain.WitnessCreator", "WitnessCreator", "1.0.4")]
public class WitnessCreatorPlugin : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <ShowAfterDelay>d__15 : IEnumerator<object>, IEnumerator, IDisposable
	{
		private int <>1__state;

		private object <>2__current;

		public WitnessCreatorPlugin <>4__this;

		public ERole role;

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

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

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

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Expected O, but got Unknown
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			int num = <>1__state;
			WitnessCreatorPlugin witnessCreatorPlugin = <>4__this;
			switch (num)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(4f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((Object)(object)GameUI.instance == (Object)null || witnessCreatorPlugin._showUI || witnessCreatorPlugin._panelShownThisRound)
				{
					return false;
				}
				witnessCreatorPlugin.OpenFor(role);
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	public static WitnessCreatorPlugin Instance;

	private bool _showUI;

	private ERole _role;

	private string _name = "";

	private byte[] _png;

	private Texture2D _preview;

	private bool _prevCursorVisible;

	private CursorLockMode _prevLock;

	private Rect _win;

	private string _accusation = "";

	private bool _panelShownThisRound;

	private Texture2D _bgTex;

	private void Awake()
	{
		//IL_0016: 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_0050: Expected O, but got Unknown
		Instance = this;
		Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		new Harmony("Dorfistain.WitnessCreator").PatchAll();
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "witness_panel.png");
		if (File.Exists(path))
		{
			_bgTex = new Texture2D(2, 2);
			ImageConversion.LoadImage(_bgTex, File.ReadAllBytes(path));
		}
		Writer<WitnessUploadMsg>.write = WitnessReadWrite.WriteUpload;
		Reader<WitnessUploadMsg>.read = WitnessReadWrite.ReadUpload;
		Writer<WitnessOverrideMsg>.write = WitnessReadWrite.WriteOverride;
		Reader<WitnessOverrideMsg>.read = WitnessReadWrite.ReadOverride;
		((BaseUnityPlugin)this).Logger.LogInfo((object)"WitnessCreator v1.0 loaded — prosecutor & defense each set their own witness.");
	}

	private void Update()
	{
		//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_0046: Unknown result type (might be due to invalid IL or missing references)
		//IL_0048: Invalid comparison between Unknown and I4
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Invalid comparison between Unknown and I4
		//IL_005e: Unknown result type (might be due to invalid IL or missing references)
		if (_showUI && (Object)(object)GameUI.instance == (Object)null)
		{
			CloseUI();
		}
		if (!Input.GetKeyDown((KeyCode)287) || !((Object)(object)GameUI.instance != (Object)null))
		{
			return;
		}
		Player localPlayer = Player.LocalPlayer;
		ERole val = (ERole)((localPlayer != null) ? ((int)localPlayer.playerRole) : 0);
		if ((int)val == 1 || (int)val == 2)
		{
			if (_showUI)
			{
				CloseUI();
			}
			else
			{
				OpenFor(val);
			}
		}
	}

	public void TryAutoShowAfterCharges(string accusation)
	{
		//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_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Invalid comparison between Unknown and I4
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Invalid comparison between Unknown and I4
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)GameUI.instance == (Object)null)
		{
			return;
		}
		Player localPlayer = Player.LocalPlayer;
		ERole val = (ERole)((localPlayer != null) ? ((int)localPlayer.playerRole) : 0);
		if ((int)val == 1 || (int)val == 2)
		{
			_accusation = accusation;
			if (!_showUI && !_panelShownThisRound)
			{
				((MonoBehaviour)this).StartCoroutine(ShowAfterDelay(val));
			}
		}
	}

	[IteratorStateMachine(typeof(<ShowAfterDelay>d__15))]
	private IEnumerator ShowAfterDelay(ERole role)
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ShowAfterDelay>d__15(0)
		{
			<>4__this = this,
			role = role
		};
	}

	public void ResetForNewRound()
	{
		_accusation = "";
		_panelShownThisRound = false;
		if (_showUI)
		{
			CloseUI();
		}
	}

	private void OpenFor(ERole role)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0002: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: 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_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)
		_role = role;
		_name = "";
		_png = null;
		_preview = null;
		_panelShownThisRound = true;
		_prevCursorVisible = Cursor.visible;
		_prevLock = Cursor.lockState;
		Cursor.visible = true;
		Cursor.lockState = (CursorLockMode)0;
		Player localPlayer = Player.LocalPlayer;
		if (localPlayer != null)
		{
			CustomPlayerCamera componentInChildren = ((Component)localPlayer).GetComponentInChildren<CustomPlayerCamera>();
			if (componentInChildren != null)
			{
				componentInChildren.ManageCameraControls(false);
			}
		}
		_win = new Rect((float)Screen.width * 0.5f - 600f, (float)Screen.height * 0.5f - 503f, 1200f, 1006f);
		_showUI = true;
	}

	private void CloseUI()
	{
		//IL_0017: 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)
		_showUI = false;
		_preview = null;
		_png = null;
		_role = (ERole)0;
		Cursor.visible = _prevCursorVisible;
		Cursor.lockState = _prevLock;
		Player localPlayer = Player.LocalPlayer;
		if (localPlayer != null)
		{
			CustomPlayerCamera componentInChildren = ((Component)localPlayer).GetComponentInChildren<CustomPlayerCamera>();
			if (componentInChildren != null)
			{
				componentInChildren.ManageCameraControls(true);
			}
		}
	}

	private void OnGUI()
	{
		//IL_0009: Unknown result type (might be due to invalid IL or missing references)
		//IL_0022: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_005d: 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_007d: Expected O, but got Unknown
		//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)
		if (_showUI)
		{
			Color color = GUI.color;
			GUI.color = new Color(0f, 0f, 0f, 0.5f);
			GUI.DrawTexture(new Rect(0f, 0f, (float)Screen.width, (float)Screen.height), (Texture)(object)Texture2D.whiteTexture);
			GUI.color = color;
			_win = GUI.Window(186089045, _win, new WindowFunction(DrawWindow), GUIContent.none, GUIStyle.none);
		}
	}

	private void DrawWindow(int _id)
	{
		//IL_0022: 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_0047: Invalid comparison between Unknown and I4
		//IL_0089: 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_00b7: 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_017c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_01e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_0213: 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)
		if ((Object)(object)_bgTex != (Object)null)
		{
			GUI.DrawTexture(new Rect(0f, 0f, 1200f, 1006f), (Texture)(object)_bgTex, (ScaleMode)0);
		}
		string text = ((!string.IsNullOrEmpty(_accusation)) ? _accusation : ((((int)_role == 1) ? "PROSECUTION" : "DEFENSE") + " WITNESS"));
		GUIStyle val = SAccusation();
		val.wordWrap = true;
		GUI.Label(new Rect(40f, 892f, 1120f, 104f), text, val);
		if ((Object)(object)_preview != (Object)null)
		{
			GUI.DrawTexture(new Rect(436f, 132f, 316f, 312f), (Texture)(object)_preview, (ScaleMode)2);
			if (GUI.Button(new Rect(708f, 132f, 44f, 44f), "x", SClearBtn()))
			{
				_png = null;
				_preview = null;
			}
		}
		else if (GUI.Button(new Rect(436f, 132f, 316f, 312f), "Load Photo...", SPhotoBtn()))
		{
			PickPhoto();
		}
		if (string.IsNullOrEmpty(_name))
		{
			GUI.Label(new Rect(392f, 516f, 404f, 56f), "Type witness name...", SPlaceholder());
		}
		_name = GUI.TextField(new Rect(376f, 508f, 436f, 72f), _name ?? "", STransparentField());
		if (!string.IsNullOrEmpty(_name) && _name.Length > 15)
		{
			_name = _name.Substring(0, 15);
		}
		if (GUI.Button(new Rect(352f, 666f, 220f, 220f), GUIContent.none, GUIStyle.none))
		{
			CloseUI();
		}
		if (GUI.Button(new Rect(626f, 666f, 220f, 220f), GUIContent.none, GUIStyle.none))
		{
			Submit();
		}
		GUI.DragWindow(new Rect(0f, 0f, 1200f, 120f));
	}

	private void PickPhoto()
	{
		//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_005b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0061: Expected O, but got Unknown
		string[] array = StandaloneFileBrowser.OpenFilePanel("Select Witness Photo", "", (ExtensionFilter[])(object)new ExtensionFilter[1]
		{
			new ExtensionFilter("Images", new string[3] { "png", "jpg", "jpeg" })
		}, false);
		if (array == null || array.Length == 0 || !File.Exists(array[0]))
		{
			return;
		}
		try
		{
			Texture2D val = new Texture2D(2, 2);
			if (ImageConversion.LoadImage(val, File.ReadAllBytes(array[0])))
			{
				_png = Encode256(val);
				_preview = val;
			}
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("[WitnessCreator] Failed to load photo: " + ex.Message));
		}
	}

	private void Submit()
	{
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Invalid comparison between Unknown and I4
		bool flag = !string.IsNullOrWhiteSpace(_name);
		bool flag2 = _png != null && _png.Length != 0;
		if (flag || flag2)
		{
			string text = (flag ? _name.Trim() : null);
			if (!string.IsNullOrEmpty(text) && text.Length > 15)
			{
				text = text.Substring(0, 15);
			}
			WitnessUploadMsg witnessUploadMsg = default(WitnessUploadMsg);
			witnessUploadMsg.isProc = (int)_role == 1;
			witnessUploadMsg.witnessName = text;
			witnessUploadMsg.pngBytes = (flag2 ? _png : new byte[0]);
			NetworkClient.Send<WitnessUploadMsg>(witnessUploadMsg, 0);
		}
		CloseUI();
	}

	public static void SrvOnUpload(NetworkConnectionToClient conn, WitnessUploadMsg msg)
	{
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_0033: 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)
		if (!NetworkServer.active)
		{
			return;
		}
		NetworkIdentity identity = ((NetworkConnection)conn).identity;
		Player val = ((identity != null) ? ((Component)identity).GetComponent<Player>() : null);
		if (!((Object)(object)val == (Object)null))
		{
			ERole val2 = (ERole)(msg.isProc ? 1 : 2);
			if (val.playerRole == val2)
			{
				WitnessOverrideMsg witnessOverrideMsg = default(WitnessOverrideMsg);
				witnessOverrideMsg.isProc = msg.isProc;
				witnessOverrideMsg.witnessName = msg.witnessName;
				witnessOverrideMsg.pngBytes = msg.pngBytes;
				NetworkServer.SendToAll<WitnessOverrideMsg>(witnessOverrideMsg, 0, false);
			}
		}
	}

	public static void CliOnOverride(WitnessOverrideMsg msg)
	{
		//IL_005e: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_010b: Unknown result type (might be due to invalid IL or missing references)
		//IL_013f: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			byte[] pngBytes = msg.pngBytes;
			Texture2D tex = ((pngBytes != null && pngBytes.Length != 0) ? DecodeTex(msg.pngBytes) : null);
			string text = msg.witnessName;
			if (!string.IsNullOrEmpty(text) && text.Length > 15)
			{
				text = text.Substring(0, 15);
			}
			WitnessOverrides.Set(msg.isProc, text, tex);
			ERole val = (ERole)(msg.isProc ? 1 : 2);
			FieldInfo field = typeof(WitnessUI).GetField("role", BindingFlags.Instance | BindingFlags.NonPublic);
			WitnessUI[] array = Object.FindObjectsByType<WitnessUI>((FindObjectsSortMode)0);
			foreach (WitnessUI val2 in array)
			{
				if ((ERole)(field?.GetValue(val2) ?? ((object)(ERole)0)) == val)
				{
					ApplyOverride(val2, val);
				}
			}
			FieldInfo field2 = typeof(WitnessBot).GetField("playingFor", BindingFlags.Instance | BindingFlags.NonPublic);
			WitnessBot[] array2 = Object.FindObjectsByType<WitnessBot>((FindObjectsSortMode)0);
			foreach (WitnessBot obj in array2)
			{
				if ((ERole)(field2?.GetValue(obj) ?? ((object)(ERole)0)) == val)
				{
					object? obj2 = typeof(WitnessBot).GetField("witnessSign", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(obj);
					WitnessSign val3 = (WitnessSign)((obj2 is WitnessSign) ? obj2 : null);
					if (val3 != null)
					{
						ApplySignOverride(val3, val);
					}
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[WitnessCreator] CliOnOverride error: " + ex));
		}
	}

	internal static void ApplySignOverride(WitnessSign sign, ERole role)
	{
		//IL_0000: 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_00b0: Unknown result type (might be due to invalid IL or missing references)
		Texture2D val = WitnessOverrides.Tex(role);
		if ((Object)(object)val == (Object)null || (Object)(object)sign == (Object)null)
		{
			return;
		}
		Type typeFromHandle = typeof(WitnessSign);
		try
		{
			object? obj = typeFromHandle.GetField("frontMat", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(sign);
			Material val2 = (Material)((obj is Material) ? obj : null);
			object? obj2 = typeFromHandle.GetField("backMat", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(sign);
			Material val3 = (Material)((obj2 is Material) ? obj2 : null);
			Material[] array = (Material[])(object)new Material[2] { val2, val3 };
			foreach (Material val4 in array)
			{
				if (!((Object)(object)val4 == (Object)null))
				{
					val4.SetTexture("_BaseMap", (Texture)(object)val);
					val4.SetTextureOffset("_BaseMap", Vector2.zero);
					val4.SetTextureScale("_BaseMap", Vector2.one);
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[WitnessCreator] ApplySignOverride error: " + ex.Message));
		}
	}

	internal static void ApplyOverride(WitnessUI w, ERole role)
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Unknown result type (might be due to invalid IL or missing references)
		//IL_007f: 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)
		if ((Object)(object)w == (Object)null)
		{
			return;
		}
		string text = WitnessOverrides.Name(role);
		Texture2D val = WitnessOverrides.Tex(role);
		if (text == null && (Object)(object)val == (Object)null)
		{
			return;
		}
		Type typeFromHandle = typeof(WitnessUI);
		try
		{
			if ((Object)(object)val != (Object)null)
			{
				object? obj = typeFromHandle.GetField("witnessPic", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(w);
				Image val2 = (Image)((obj is Image) ? obj : null);
				if (val2 != null && (Object)(object)val2 != (Object)null)
				{
					val2.sprite = Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
				}
			}
			if (text != null)
			{
				object? obj2 = typeFromHandle.GetField("witnessTitleText", BindingFlags.Instance | BindingFlags.NonPublic)?.GetValue(w);
				TMP_Text val3 = (TMP_Text)((obj2 is TMP_Text) ? obj2 : null);
				if (val3 != null && (Object)(object)val3 != (Object)null)
				{
					val3.text = text;
				}
			}
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[WitnessCreator] ApplyOverride error: " + ex.Message));
		}
	}

	private static byte[] Encode256(Texture2D src)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_0031: 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_004b: 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_006e: Expected O, but got Unknown
		RenderTexture val = new RenderTexture(256, 256, 24);
		RenderTexture active = RenderTexture.active;
		RenderTexture.active = val;
		Graphics.Blit((Texture)(object)src, val);
		Texture2D val2 = new Texture2D(256, 256, (TextureFormat)4, false);
		val2.ReadPixels(new Rect(0f, 0f, 256f, 256f), 0, 0);
		val2.Apply();
		RenderTexture.active = active;
		val.Release();
		return ImageConversion.EncodeToPNG(val2);
	}

	internal static Texture2D DecodeTex(byte[] png)
	{
		//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_0019: Expected O, but got Unknown
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0021: Expected O, but got Unknown
		Texture2D val = new Texture2D(256, 256, (TextureFormat)4, false, false);
		ImageConversion.LoadImage(val, png);
		val.Apply();
		return val;
	}

	private static GUIStyle STransparentField()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_0031: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_0055: Unknown result type (might be due to invalid IL or missing references)
		//IL_006a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: 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_0094: Expected O, but got Unknown
		GUIStyle val = new GUIStyle(GUI.skin.textField)
		{
			fontSize = 30,
			fontStyle = (FontStyle)1,
			alignment = (TextAnchor)4
		};
		val.normal.background = null;
		val.hover.background = null;
		val.focused.background = null;
		val.active.background = null;
		val.normal.textColor = new Color(0.16f, 0.1f, 0.04f);
		val.focused.textColor = new Color(0.16f, 0.1f, 0.04f);
		return val;
	}

	private static GUIStyle SPlaceholder()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_0025: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Expected O, but got Unknown
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			fontSize = 26,
			fontStyle = (FontStyle)2,
			alignment = (TextAnchor)4
		};
		val.normal.textColor = new Color(0.45f, 0.32f, 0.2f, 0.7f);
		return val;
	}

	private static GUIStyle SPhotoBtn()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		GUIStyle val = new GUIStyle(GUI.skin.button)
		{
			fontSize = 24,
			fontStyle = (FontStyle)1
		};
		val.normal.textColor = new Color(0.28f, 0.14f, 0.04f);
		return val;
	}

	private static GUIStyle SClearBtn()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0017: 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_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003e: Expected O, but got Unknown
		GUIStyle val = new GUIStyle(GUI.skin.button)
		{
			fontSize = 22,
			fontStyle = (FontStyle)1
		};
		val.normal.textColor = new Color(0.65f, 0.08f, 0.08f);
		return val;
	}

	private static GUIStyle SAccusation()
	{
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: 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_002c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_004c: Expected O, but got Unknown
		GUIStyle val = new GUIStyle(GUI.skin.label)
		{
			fontStyle = (FontStyle)2,
			fontSize = 22,
			wordWrap = true,
			alignment = (TextAnchor)4
		};
		val.normal.textColor = new Color(0.3f, 0.14f, 0.04f);
		return val;
	}
}
[HarmonyPatch(typeof(GameUI), "Awake")]
internal static class Patch_GameUI_Awake
{
	private static void Postfix()
	{
		NetworkClient.RegisterHandler<WitnessOverrideMsg>((Action<WitnessOverrideMsg>)WitnessCreatorPlugin.CliOnOverride, true);
	}
}
[HarmonyPatch(typeof(GameManager), "Awake")]
internal static class Patch_GameManager_Awake
{
	private static void Postfix()
	{
		WitnessOverrides.Clear();
		WitnessCreatorPlugin.Instance?.ResetForNewRound();
		if (NetworkServer.active)
		{
			NetworkServer.RegisterHandler<WitnessUploadMsg>((Action<NetworkConnectionToClient, WitnessUploadMsg>)WitnessCreatorPlugin.SrvOnUpload, true);
		}
	}
}
[HarmonyPatch(typeof(GameUI), "UpdateChargesUI")]
internal static class Patch_GameUI_UpdateChargesUI
{
	private static void Postfix(string newValue)
	{
		WitnessCreatorPlugin.Instance?.TryAutoShowAfterCharges(newValue);
	}
}
[HarmonyPatch(typeof(WitnessUI), "InitWitnessUi")]
internal static class Patch_WitnessUI_InitWitnessUi
{
	private static void Postfix(WitnessUI __instance, ERole role)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		WitnessCreatorPlugin.ApplyOverride(__instance, role);
	}
}
[HarmonyPatch(typeof(WitnessSign), "SetWitnessSign")]
internal static class Patch_WitnessSign_SetWitnessSign
{
	private static void Postfix(WitnessSign __instance, ERole role)
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		WitnessCreatorPlugin.ApplySignOverride(__instance, role);
	}
}