Decompiled source of ImageToPlanePlugin v3.0.0

ImageToPlane.dll

Decompiled a month 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.InteropServices;
using System.Runtime.Versioning;
using System.Windows.Forms;
using BepInEx;
using BepInEx.Configuration;
using Bounce.Singletons;
using ModdingTales;
using SRF;
using UnityEngine;
using UnityEngine.Video;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RForRotatePlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("D20ArmyKnife")]
[assembly: AssemblyProduct("RForRotatePlugin")]
[assembly: AssemblyCopyright("Copyright ©  2020")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("4e4deb5e-97f9-4901-bf67-6748a9c1229a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace ImageToPlane;

[BepInPlugin("org.hollofox.plugins.imageToPlane", "Image To Plane Plugin", "3.0.0.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ImageToPlane : BaseUnityPlugin
{
	private const string Guid = "org.hollofox.plugins.imageToPlane";

	private const string Version = "3.0.0.0";

	private GameObject _cube;

	private bool _rendered;

	private readonly TimeSpan _fetchTimeSpan = TimeSpan.FromSeconds(1.0);

	private DateTime _lastChecked = DateTime.Now;

	private List<Vector4> movement = new List<Vector4>();

	private bool isMoving;

	private static bool _load;

	private static Texture2D _bufferTexture;

	private ConfigEntry<KeyboardShortcut> LoadImage { get; set; }

	private ConfigEntry<KeyboardShortcut> ClearImage { get; set; }

	private ConfigEntry<KeyboardShortcut> MoveImage { get; set; }

	private ConfigEntry<int> PixelsPerTile { get; set; }

	private ConfigEntry<float> TilesWide { get; set; }

	private ConfigEntry<float> TilesLong { get; set; }

	private void Awake()
	{
		DoConfig(((BaseUnityPlugin)this).Config);
		ModdingUtils.AddPluginToMenuList((BaseUnityPlugin)(object)this, "HolloFoxes'");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"ImageToPlane Plug-in loaded");
	}

	private void DoConfig(ConfigFile config)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_001d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Expected O, but got Unknown
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Expected O, but got Unknown
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		//IL_0057: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		ConfigDescription val = new ConfigDescription("logging level, inherited determined by setinjectionflag", (AcceptableValueBase)null, Array.Empty<object>());
		ConfigDescription val2 = new ConfigDescription("keybind to spawn plane", (AcceptableValueBase)null, Array.Empty<object>());
		ConfigDescription val3 = new ConfigDescription("keybind to remove plane", (AcceptableValueBase)null, Array.Empty<object>());
		ConfigDescription val4 = new ConfigDescription("keybind to move plane", (AcceptableValueBase)null, Array.Empty<object>());
		ConfigDescription val5 = new ConfigDescription("pixel resolution per tile", (AcceptableValueBase)null, Array.Empty<object>());
		ConfigDescription val6 = new ConfigDescription("Tile Dimension for Video", (AcceptableValueBase)null, Array.Empty<object>());
		LoadImage = config.Bind<KeyboardShortcut>("Hotkeys", "Load Image Shortcut", new KeyboardShortcut((KeyCode)282, Array.Empty<KeyCode>()), val2);
		ClearImage = config.Bind<KeyboardShortcut>("Hotkeys", "Clear Image Shortcut", new KeyboardShortcut((KeyCode)283, Array.Empty<KeyCode>()), val3);
		MoveImage = config.Bind<KeyboardShortcut>("Hotkeys", "Move Image Shortcut", new KeyboardShortcut((KeyCode)284, Array.Empty<KeyCode>()), val4);
		PixelsPerTile = config.Bind<int>("Scale", "Scale Size", 40, val5);
		TilesWide = config.Bind<float>("Video", "Tiles Wide", 32f, val6);
		TilesLong = config.Bind<float>("Video", "Tiles High", 18f, val6);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Config Bound");
	}

	private bool OnBoard()
	{
		return SimpleSingletonBehaviour<CameraController>.HasInstance && SingletonStateMBehaviour<BoardSessionManager, State<BoardSessionManager>>.HasInstance && BoardSessionManager.HasBoardAndIsInNominalState && !BoardSessionManager.IsLoading;
	}

	private void Update()
	{
		//IL_0016: Unknown result type (might be due to invalid IL or missing references)
		//IL_001b: 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_00fc: Unknown result type (might be due to invalid IL or missing references)
		//IL_0101: Unknown result type (might be due to invalid IL or missing references)
		//IL_0105: 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_0036: 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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_005c: Expected O, but got Unknown
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0067: Invalid comparison between Unknown and I4
		//IL_0285: Unknown result type (might be due to invalid IL or missing references)
		//IL_0296: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a7: Unknown result type (might be due to invalid IL or missing references)
		//IL_02bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_02d0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0180: Unknown result type (might be due to invalid IL or missing references)
		//IL_0185: Unknown result type (might be due to invalid IL or missing references)
		//IL_0189: Unknown result type (might be due to invalid IL or missing references)
		if (OnBoard())
		{
			try
			{
				KeyboardShortcut value = LoadImage.Value;
				if (Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
				{
					OpenFileDialog val = new OpenFileDialog
					{
						Filter = "Image Files|*.bmp;*.jpg;*.jpeg;*.png;|Video Files (*.*)|*.mp4;*.mov;*.webm;*.wmv;|All Files (*.*)|*.*",
						InitialDirectory = "C:",
						Title = "Select Media"
					};
					string text = null;
					if ((int)((CommonDialog)val).ShowDialog() == 1)
					{
						text = ((FileDialog)val).FileName;
					}
					((BaseUnityPlugin)this).Logger.LogDebug((object)text);
					if (string.IsNullOrWhiteSpace(text))
					{
						return;
					}
					if (text.EndsWith(".mp4") || text.EndsWith(".mov;") || text.EndsWith(".webm;") || text.EndsWith(".wmv;"))
					{
						MakeMap(text);
					}
					else
					{
						MakeMap(File.ReadAllBytes(text));
					}
				}
				else
				{
					value = ClearImage.Value;
					if (Input.GetKey(((KeyboardShortcut)(ref value)).MainKey) && _rendered)
					{
						Cleanup();
					}
					else if (DateTime.Now - _lastChecked > _fetchTimeSpan)
					{
						_lastChecked = DateTime.Now;
					}
					else if (_load)
					{
						MakeMap(_bufferTexture);
						_load = false;
					}
				}
				value = MoveImage.Value;
				if (Input.GetKey(((KeyboardShortcut)(ref value)).MainKey))
				{
					SystemMessage.AskForTextInput("Tween Plane", "Enter the movement e.g. [x,y,z,t] => [1,1,1,1]", "OK", (Action<string>)delegate(string tween)
					{
						//IL_009b: Unknown result type (might be due to invalid IL or missing references)
						string[] array = tween.Replace("[", "").Replace("]", "").Split(',');
						for (int i = 0; i < array.Length; i++)
						{
							array[i] = array[i].Replace(",", "");
						}
						float num = float.Parse(array[0]);
						float num2 = float.Parse(array[1]);
						float num3 = float.Parse(array[2]);
						float num4 = 0f;
						if (array.Length == 4)
						{
							num4 = float.Parse(array[3]);
						}
						movement.Add(new Vector4(num, num2, num3, num4));
					}, (Action)delegate
					{
					}, "Cancel", (Action)null, "");
				}
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)"Crash in Image To Plane Plugin");
				((BaseUnityPlugin)this).Logger.LogError((object)ex.Message);
				((BaseUnityPlugin)this).Logger.LogError((object)ex.StackTrace);
				((BaseUnityPlugin)this).Logger.LogError((object)ex.InnerException);
				((BaseUnityPlugin)this).Logger.LogError((object)ex.Source);
			}
		}
		if (!isMoving && !((Object)(object)_cube == (Object)null) && movement.Count != 0)
		{
			Vector3 move = default(Vector3);
			((Vector3)(ref move))..ctor(movement[0].x, movement[0].y, movement[0].z);
			float w = movement[0].w;
			((MonoBehaviour)this).StartCoroutine(moveObject(_cube, move, w));
			movement.RemoveAt(0);
		}
	}

	internal IEnumerator moveObject(GameObject o, Vector3 move, float totalMovementTime)
	{
		//IL_0015: 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)
		((BaseUnityPlugin)this).Logger.LogInfo((object)"ITP Moving cube");
		isMoving = true;
		Vector3 origin = o.transform.localPosition;
		Vector3 destination = origin + move;
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"dest:[{destination.x},{destination.y},{destination.z}]");
		float currentMovementTime = 0f;
		while (Vector3.Distance(o.transform.localPosition, destination) > 0f)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"ITP Moving cube Loop");
			currentMovementTime += Time.deltaTime;
			o.transform.localPosition = Vector3.Lerp(origin, destination, currentMovementTime / totalMovementTime);
			yield return null;
		}
		o.transform.localPosition = destination;
		isMoving = false;
	}

	private void MakeMap(byte[] fileContent)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_0009: Expected O, but got Unknown
		Texture2D val = new Texture2D(0, 0);
		ImageConversion.LoadImage(val, fileContent);
		MakeMap(val);
	}

	private void AdjustVideoSize(object o)
	{
		//IL_005a: Unknown result type (might be due to invalid IL or missing references)
		VideoPlayer val = default(VideoPlayer);
		if (!((Object)(object)_cube == (Object)null) && _cube.TryGetComponent<VideoPlayer>(ref val))
		{
			_cube.transform.localScale = new Vector3(TilesWide.Value + 0.01f, 0.01f, TilesLong.Value + 0.01f);
		}
	}

	private void AdjustMapSize(object o)
	{
		//IL_0081: Unknown result type (might be due to invalid IL or missing references)
		VideoPlayer val = default(VideoPlayer);
		if (!((Object)(object)_cube == (Object)null) && !_cube.TryGetComponent<VideoPlayer>(ref val))
		{
			Renderer component = _cube.GetComponent<Renderer>();
			Texture mainTexture = component.material.mainTexture;
			_cube.transform.localScale = new Vector3((float)mainTexture.width / (float)PixelsPerTile.Value + 0.01f, 0.01f, (float)mainTexture.height / (float)PixelsPerTile.Value + 0.01f);
		}
	}

	internal void MakeMap(string uri)
	{
		if ((Object)(object)_cube == (Object)null)
		{
			_cube = GameObject.CreatePrimitive((PrimitiveType)3);
		}
		VideoPlayer val = default(VideoPlayer);
		if (!_cube.TryGetComponent<VideoPlayer>(ref val))
		{
			val = _cube.AddComponent<VideoPlayer>();
		}
		val.playOnAwake = true;
		val.source = (VideoSource)1;
		if (!uri.StartsWith("http"))
		{
			uri = "file://" + uri;
		}
		val.url = uri;
		val.isLooping = true;
		AdjustVideoSize(null);
		bool flag = true;
		_cube.layer = 16;
		_rendered = true;
		_load = false;
	}

	private void MakeMap(Texture2D texture)
	{
		if ((Object)(object)_cube == (Object)null)
		{
			_cube = GameObject.CreatePrimitive((PrimitiveType)3);
		}
		SRFGameObjectExtensions.RemoveComponentIfExists<VideoPlayer>(_cube);
		Renderer component = _cube.GetComponent<Renderer>();
		component.material.mainTexture = (Texture)(object)texture;
		component.material.SetTexture("main", (Texture)(object)texture);
		AdjustMapSize(null);
		_rendered = true;
		_load = false;
	}

	private void Cleanup()
	{
		GameObject cube = _cube;
		_cube = null;
		if ((Object)(object)cube != (Object)null)
		{
			Object.Destroy((Object)(object)cube);
		}
		_rendered = false;
	}
}