Decompiled source of Paint v1.0.0

Paint.dll

Decompiled 2 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Paint")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Paint")]
[assembly: AssemblyCopyright("Copyright ©  2023")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("f5817b21-d1dd-4eb2-bfb8-b677530a3b07")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
public class CustomStain
{
	public Vector3 Position { get; set; }

	public Vector3 LocalPosition { get; set; }

	[JsonIgnore]
	public Transform Transform { get; set; }

	public float Offset { get; set; }

	public float Size { get; set; }

	public Color Color { get; set; }

	public bool IsStatic { get; set; }

	public Vector3 Normal { get; set; }

	[JsonConstructor]
	public CustomStain()
	{
	}

	public CustomStain(Vector3 position, Color color, float offset, float size, Transform transform, Vector3 localPosition, Vector3 normal)
	{
		//IL_0009: 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_0033: 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)
		Position = position;
		Color = color;
		IsStatic = true;
		Size = size;
		Transform = transform;
		LocalPosition = localPosition;
		Normal = normal;
		Offset = offset;
	}
}
public class Vector3Converter : JsonConverter<Vector3>
{
	public override void WriteJson(JsonWriter writer, Vector3 value, JsonSerializer serializer)
	{
		//IL_0015: 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_0047: Unknown result type (might be due to invalid IL or missing references)
		writer.WriteStartObject();
		writer.WritePropertyName("x");
		writer.WriteValue(value.x);
		writer.WritePropertyName("y");
		writer.WriteValue(value.y);
		writer.WritePropertyName("z");
		writer.WriteValue(value.z);
		writer.WriteEndObject();
	}

	public override Vector3 ReadJson(JsonReader reader, Type objectType, Vector3 existingValue, bool hasExistingValue, JsonSerializer serializer)
	{
		//IL_003b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		JObject val = JObject.Load(reader);
		return new Vector3((float)val["x"], (float)val["y"], (float)val["z"]);
	}
}
public class ColorConverter : JsonConverter<Color>
{
	public override void WriteJson(JsonWriter writer, Color value, JsonSerializer serializer)
	{
		//IL_0015: 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_0047: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		writer.WriteStartObject();
		writer.WritePropertyName("r");
		writer.WriteValue(value.r);
		writer.WritePropertyName("g");
		writer.WriteValue(value.g);
		writer.WritePropertyName("b");
		writer.WriteValue(value.b);
		writer.WritePropertyName("a");
		writer.WriteValue(value.a);
		writer.WriteEndObject();
	}

	public override Color ReadJson(JsonReader reader, Type objectType, Color existingValue, bool hasExistingValue, JsonSerializer serializer)
	{
		//IL_004c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0051: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Unknown result type (might be due to invalid IL or missing references)
		JObject val = JObject.Load(reader);
		return new Color((float)val["r"], (float)val["g"], (float)val["b"], (float)val["a"]);
	}
}
namespace Paint
{
	[BepInPlugin("com.banana.Paint", "Paint", "1.0.0")]
	public class PaintPlugin : BaseUnityPlugin
	{
		public enum Tool
		{
			Brush,
			Eraser,
			Bucket,
			None
		}

		private const string MyGUID = "com.banana.Paint";

		private const string PluginName = "Paint";

		private const string VersionString = "1.0.0";

		private static readonly Harmony Harmony = new Harmony("com.banana.Paint");

		public static ManualLogSource Log = new ManualLogSource("Paint");

		private static List<CustomStain> paints = new List<CustomStain>();

		public Color currentColor = Color.red;

		public float brushSize = 1f;

		private const float voxelSize = 2.75f;

		public float paintOffset = 0.01f;

		public Image image;

		private GameObject Manager = null;

		private GameObject picker = null;

		public Material PreviewMat;

		private ConfigEntry<KeyCode> saveKey;

		private ConfigEntry<KeyCode> loadKey;

		private GameObject Point1 = null;

		private GameObject Point2 = null;

		private GameObject connectingCube = null;

		private float offset = 0.1f;

		public static GameObject weaponPrefabBrush;

		public static GameObject weaponPrefabBucket;

		public static GameObject weaponPrefabEraser;

		public static GameObject Brush;

		public static GameObject Bucket;

		public static GameObject Eraser;

		public static int defaultSlot = 1;

		private GameObject brushCanvas;

		private GameObject TheBrushCanvas;

		private static StyleHUD styleHUD;

		public Tool tool = Tool.None;

		public static PaintPlugin Instance { get; private set; }

		private void Awake()
		{
			saveKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("settings", "Save key", (KeyCode)279, (ConfigDescription)null);
			loadKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("settings", "Load key", (KeyCode)281, (ConfigDescription)null);
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Plugin " + ((BaseUnityPlugin)this).Info.Metadata.GUID + " is loaded!"));
			Harmony.PatchAll();
			SceneManager.sceneLoaded += SceneManager_sceneLoaded;
			Assembly executingAssembly = Assembly.GetExecutingAssembly();
			AssetBundle val = AssetBundle.LoadFromStream(executingAssembly.GetManifestResourceStream("Paint.Bundles.paint.bundle"));
			Object[] array = val.LoadAllAssets();
			foreach (Object val2 in array)
			{
				GameObject val3 = (GameObject)(object)((val2 is GameObject) ? val2 : null);
				if (val3 != null)
				{
					switch (((Object)val3).name)
					{
					case "Brush":
						Brush = val3;
						break;
					case "Bucket":
						Bucket = val3;
						break;
					case "Eraser":
						Eraser = val3;
						break;
					case "BrushUI":
						brushCanvas = val3;
						break;
					}
				}
			}
		}

		private void SceneManager_sceneLoaded(Scene arg0, LoadSceneMode arg1)
		{
			paints.Clear();
			if ((Object)(object)PreviewMat == (Object)null)
			{
				((MonoBehaviour)this).StartCoroutine(loadPrevMat());
			}
		}

		public IEnumerator loadPrevMat()
		{
			AsyncOperationHandle<Material> operationHandle = Addressables.LoadAssetAsync<Material>((object)"Assets/Materials/Preview Object.mat");
			yield return (object)new WaitUntil((Func<bool>)(() => operationHandle.IsDone));
			PreviewMat = operationHandle.Result;
		}

		private Vector3? GetLookAtNormal()
		{
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return null;
			}
			Ray val = main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
			int num = 16777472;
			RaycastHit val2 = default(RaycastHit);
			if (Physics.Raycast(val, ref val2, 100f, num))
			{
				return ((RaycastHit)(ref val2)).normal;
			}
			return null;
		}

		public void WriteSaveJson(List<CustomStain> paintsToSave)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Expected O, but got Unknown
			try
			{
				if (!GetLookAtNormal().HasValue)
				{
					Debug.LogWarning((object)"No surface found to determine normal.");
					return;
				}
				if (paintsToSave.Count == 0)
				{
					Debug.LogWarning((object)"No paints found with the current look-at normal.");
					return;
				}
				string contents = JsonConvert.SerializeObject((object)paintsToSave, (Formatting)1, new JsonSerializerSettings
				{
					Converters = new List<JsonConverter>
					{
						(JsonConverter)(object)new Vector3Converter(),
						(JsonConverter)(object)new ColorConverter()
					}
				});
				File.WriteAllText(Path.Combine(Paths.ConfigPath, "saveFile.txt"), contents);
				Debug.Log((object)$"Data successfully saved to {Paths.ConfigPath}saveFile.txt. Saved {paintsToSave.Count} paints.");
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Failed to save data: " + ex.Message));
			}
		}

		public List<CustomStain> ReadFromJson()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			try
			{
				string text = Path.Combine(Paths.ConfigPath, "saveFile.txt");
				if (!File.Exists(text))
				{
					Debug.LogError((object)("File not found: " + text));
					return null;
				}
				string text2 = File.ReadAllText(text);
				List<CustomStain> result = JsonConvert.DeserializeObject<List<CustomStain>>(text2, new JsonSerializerSettings
				{
					Converters = new List<JsonConverter>
					{
						(JsonConverter)(object)new Vector3Converter(),
						(JsonConverter)(object)new ColorConverter()
					}
				});
				Debug.Log((object)("Data successfully read from " + text));
				return result;
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("Failed to read data: " + ex.Message));
				return null;
			}
		}

		public static GameObject MakeGun(int var, GameObject original)
		{
			//IL_01ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cc: Unknown result type (might be due to invalid IL or missing references)
			//IL_0111: 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_013c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0141: Unknown result type (might be due to invalid IL or missing references)
			int num = 5;
			if ((Object)(object)MonoSingleton<GunControl>.Instance == (Object)null || (Object)(object)MonoSingleton<StyleHUD>.Instance == (Object)null)
			{
				return null;
			}
			if (!((Behaviour)MonoSingleton<GunControl>.Instance).enabled || !((Behaviour)MonoSingleton<StyleHUD>.Instance).enabled)
			{
				return null;
			}
			GameObject val = Object.Instantiate<GameObject>(original);
			if ((Object)(object)val == (Object)null)
			{
				return null;
			}
			Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>();
			Renderer[] array = componentsInChildren;
			foreach (Renderer val2 in array)
			{
				Material[] sharedMaterials = val2.sharedMaterials;
				Material[] array2 = sharedMaterials;
				foreach (Material material in array2)
				{
					bool flag = ((Object)material.shader).name == "psx/vertexlit/vertexlit";
					bool flag2 = ((Object)material.shader).name == "psx/unlit/unlit";
					AsyncOperationHandle<Shader> val3;
					if (flag)
					{
						val3 = Addressables.LoadAssetAsync<Shader>((object)"Assets/Shaders/Main/ULTRAKILL-vertexlit.shader");
						val3.Completed += delegate(AsyncOperationHandle<Shader> shaderOp)
						{
							//IL_0003: Unknown result type (might be due to invalid IL or missing references)
							//IL_0009: Invalid comparison between Unknown and I4
							if ((int)shaderOp.Status == 1)
							{
								Shader result2 = shaderOp.Result;
								material.shader = result2;
							}
						};
					}
					if (!flag2)
					{
						continue;
					}
					val3 = Addressables.LoadAssetAsync<Shader>((object)"Assets/Shaders/Main/ULTRAKILL-vertexlit.shader");
					val3.Completed += delegate(AsyncOperationHandle<Shader> shaderOp)
					{
						//IL_0003: Unknown result type (might be due to invalid IL or missing references)
						//IL_0009: Invalid comparison between Unknown and I4
						if ((int)shaderOp.Status == 1)
						{
							Shader result = shaderOp.Result;
							material.shader = result;
						}
					};
				}
			}
			val.transform.parent = ((Component)MonoSingleton<GunControl>.Instance).transform;
			val.transform.position = ((Component)MonoSingleton<GunControl>.Instance).transform.position;
			val.transform.localRotation = Quaternion.Euler(0f, 0f, 0f);
			MonoSingleton<GunControl>.Instance.slots[num].Add(val);
			MonoSingleton<GunControl>.Instance.allWeapons.Add(val);
			MonoSingleton<GunControl>.Instance.slotDict.Add(val, num);
			MonoSingleton<StyleHUD>.Instance.weaponFreshness.Add(val, 10f);
			val.SetActive(false);
			MonoSingleton<GunControl>.Instance.noWeapons = false;
			MonoSingleton<GunControl>.Instance.YesWeapon();
			Debug.Log((object)"made Objector");
			for (int k = 0; k < ((Component)MonoSingleton<GunControl>.Instance).transform.childCount; k++)
			{
				((Component)((Component)MonoSingleton<GunControl>.Instance).transform.GetChild(k)).gameObject.SetActive(false);
			}
			return val;
		}

		private void OpenUI()
		{
			switch (tool)
			{
			case Tool.Brush:
				OpenBrushUI();
				break;
			case Tool.Bucket:
				OpenBrushUI();
				break;
			case Tool.Eraser:
				OpenBrushUI();
				break;
			}
		}

		private void OpenBrushUI()
		{
			MonoSingleton<OptionsManager>.instance.Pause();
			if ((Object)(object)TheBrushCanvas == (Object)null)
			{
				TheBrushCanvas = Object.Instantiate<GameObject>(brushCanvas);
			}
			else
			{
				TheBrushCanvas.SetActive(true);
			}
		}

		private void Update()
		{
			//IL_01fd: Unknown result type (might be due to invalid IL or missing references)
			//IL_04f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0388: Unknown result type (might be due to invalid IL or missing references)
			//IL_038d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0392: Unknown result type (might be due to invalid IL or missing references)
			//IL_039b: 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_0424: Unknown result type (might be due to invalid IL or missing references)
			//IL_0434: Unknown result type (might be due to invalid IL or missing references)
			//IL_0439: Unknown result type (might be due to invalid IL or missing references)
			//IL_0443: Unknown result type (might be due to invalid IL or missing references)
			//IL_0448: Unknown result type (might be due to invalid IL or missing references)
			//IL_0455: Unknown result type (might be due to invalid IL or missing references)
			//IL_0465: Unknown result type (might be due to invalid IL or missing references)
			//IL_046a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0474: Unknown result type (might be due to invalid IL or missing references)
			//IL_0479: Unknown result type (might be due to invalid IL or missing references)
			//IL_0486: Unknown result type (might be due to invalid IL or missing references)
			//IL_0499: Unknown result type (might be due to invalid IL or missing references)
			//IL_04b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_04cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_04e4: 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)
			//IL_0292: Unknown result type (might be due to invalid IL or missing references)
			//IL_0297: Unknown result type (might be due to invalid IL or missing references)
			//IL_029c: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_02fb: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c9: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)TheBrushCanvas != (Object)null && Input.GetKeyDown((KeyCode)27))
			{
				TheBrushCanvas.SetActive(false);
			}
			GunControl instance = MonoSingleton<GunControl>.Instance;
			styleHUD = MonoSingleton<StyleHUD>.Instance;
			if ((Object)(object)weaponPrefabBrush == (Object)null)
			{
				weaponPrefabBrush = MakeGun(1, Brush);
			}
			if ((Object)(object)weaponPrefabBucket == (Object)null)
			{
				weaponPrefabBucket = MakeGun(1, Bucket);
			}
			if ((Object)(object)weaponPrefabEraser == (Object)null)
			{
				weaponPrefabEraser = MakeGun(1, Eraser);
			}
			if (((Object)instance.currentWeapon).name.Contains("Brush"))
			{
				tool = Tool.Brush;
			}
			else if (((Object)instance.currentWeapon).name.Contains("Eraser"))
			{
				tool = Tool.Eraser;
			}
			else if (((Object)instance.currentWeapon).name.Contains("Bucket"))
			{
				tool = Tool.Bucket;
			}
			else
			{
				tool = Tool.None;
			}
			if (MonoSingleton<OptionsManager>.Instance.paused)
			{
				return;
			}
			if (Input.GetMouseButton(0))
			{
				Draw();
			}
			if (Input.GetMouseButton(1))
			{
				OpenUI();
			}
			if (Input.GetMouseButtonUp(0) && Object.op_Implicit((Object)(object)instance.currentWeapon.GetComponent<AudioSource>()) && tool != Tool.None)
			{
				instance.currentWeapon.GetComponent<AudioSource>().Stop();
			}
			if (Input.GetMouseButtonDown(0) && Object.op_Implicit((Object)(object)instance.currentWeapon.GetComponent<AudioSource>()) && tool != Tool.None)
			{
				instance.currentWeapon.GetComponent<AudioSource>().Play();
			}
			if (Input.GetKeyDown(saveKey.Value))
			{
				if ((Object)(object)Point1 == (Object)null && (Object)(object)Point2 == (Object)null)
				{
					Point1 = GameObject.CreatePrimitive((PrimitiveType)0);
					Point1.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
					Object.Destroy((Object)(object)Point1.GetComponent<Collider>());
					Camera main = Camera.main;
					Ray val = main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
					int num = 16777472;
					RaycastHit val2 = default(RaycastHit);
					if (Physics.Raycast(val, ref val2, 100f, num))
					{
						Point1.transform.position = ((RaycastHit)(ref val2)).point;
					}
					Point2 = GameObject.CreatePrimitive((PrimitiveType)0);
					Point2.transform.localScale = new Vector3(0.1f, 0.1f, 0.1f);
					Object.Destroy((Object)(object)Point2.GetComponent<Collider>());
				}
				else
				{
					SaveSelection();
					Object.Destroy((Object)(object)Point1);
					Object.Destroy((Object)(object)Point2);
					if ((Object)(object)connectingCube != (Object)null)
					{
						Object.Destroy((Object)(object)connectingCube);
					}
				}
			}
			if ((Object)(object)Point2 != (Object)null)
			{
				Camera main2 = Camera.main;
				Ray val3 = main2.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
				int num2 = 16777472;
				RaycastHit val4 = default(RaycastHit);
				if (Physics.Raycast(val3, ref val4, 100f, num2))
				{
					Point2.transform.position = ((RaycastHit)(ref val4)).point;
					if ((Object)(object)connectingCube == (Object)null)
					{
						connectingCube = GameObject.CreatePrimitive((PrimitiveType)3);
						Renderer component = connectingCube.GetComponent<Renderer>();
						component.material = PreviewMat;
						Object.Destroy((Object)(object)connectingCube.GetComponent<Collider>());
					}
					Vector3 position = (Point1.transform.position + Point2.transform.position) / 2f;
					Vector3 val5 = (Point2.transform.position - Point1.transform.position) / 2f;
					connectingCube.transform.position = position;
					connectingCube.transform.localScale = new Vector3(Mathf.Abs(val5.x) * 2f + offset, Mathf.Abs(val5.y) * 2f + offset, Mathf.Abs(val5.z) * 2f + offset);
				}
			}
			if (Input.GetKeyDown(loadKey.Value))
			{
				DrawSave();
			}
		}

		public static void RemoveAllPaints()
		{
			foreach (CustomStain paint in paints)
			{
				Object.Destroy((Object)(object)((Component)paint.Transform).gameObject);
			}
			paints.Clear();
		}

		private List<CustomStain> GetStainsInBoundingBox()
		{
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: 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)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Point1 != (Object)null && (Object)(object)Point2 != (Object)null)
			{
				Vector3 min = Vector3.Min(Point1.transform.position, Point2.transform.position);
				Vector3 max = Vector3.Max(Point1.transform.position, Point2.transform.position);
				List<CustomStain> list = paints.Where((CustomStain stain) => stain.Position.x >= min.x - offset && stain.Position.x <= max.x + offset && stain.Position.y >= min.y - offset && stain.Position.y <= max.y + offset && stain.Position.z >= min.z - offset && stain.Position.z <= max.z + offset).ToList();
				foreach (CustomStain item in list)
				{
					item.LocalPosition = item.Position - connectingCube.transform.position;
				}
				return list;
			}
			return null;
		}

		private void SaveSelection()
		{
			WriteSaveJson(GetStainsInBoundingBox());
		}

		public void DrawSave()
		{
			//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_0033: 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_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_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Expected O, but got Unknown
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			//IL_009b: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f6: Expected O, but got Unknown
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return;
			}
			Ray val = main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
			int num = 16777472;
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.Raycast(val, ref val2, 100f, num))
			{
				return;
			}
			Vector3 point = ((RaycastHit)(ref val2)).point;
			Vector3 normal = ((RaycastHit)(ref val2)).normal;
			List<CustomStain> list = ReadFromJson();
			Debug.Log((object)normal);
			GameObject val3 = new GameObject("TempManager");
			val3.transform.position = point;
			val3.transform.rotation = Quaternion.LookRotation(normal);
			foreach (CustomStain item in list)
			{
				CustomStain customStain = DrawLocalPlane(point, normal, item, val3.transform);
				if ((Object)(object)Manager == (Object)null)
				{
					Manager = new GameObject("Manager");
					Manager.transform.position = point;
				}
				if (customStain != null)
				{
					customStain.Transform.parent = Manager.transform;
				}
			}
			Object.Destroy((Object)(object)val3);
		}

		private CustomStain DrawLocalPlane(Vector3 position, Vector3 normal, CustomStain stain, Transform tempParent)
		{
			//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_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: 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_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: 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_003a: 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_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0074: Unknown result type (might be due to invalid IL or missing references)
			//IL_0076: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Expected O, but got Unknown
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: 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_0106: Expected O, but got Unknown
			//IL_0111: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: 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_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_0172: Unknown result type (might be due to invalid IL or missing references)
			//IL_0191: Unknown result type (might be due to invalid IL or missing references)
			//IL_0196: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position2 = position;
			position += normal * stain.Offset;
			bool flag = true;
			Quaternion val = Quaternion.FromToRotation(stain.Normal, normal);
			Vector3 val2 = val * stain.LocalPosition;
			position += val2;
			int num = 16777472;
			StainVoxel val3 = MonoSingleton<StainVoxelManager>.Instance.CreateOrGetVoxel(position, false);
			if (val3 != null)
			{
				Vector3 val4 = position + normal * 3f;
				Vector3 val5 = -normal;
				RaycastHit val6 = default(RaycastHit);
				if (Physics.Raycast(val4, val5, ref val6, 5f, num))
				{
					GameObject val7 = new GameObject("ColoredVoxelProxy");
					val7.layer = 24;
					val7.transform.position = ((RaycastHit)(ref val6)).point + ((RaycastHit)(ref val6)).normal * stain.Offset;
					VoxelProxy val8 = val7.AddComponent<VoxelProxy>();
					if ((Object)(object)Manager == (Object)null)
					{
						Manager = new GameObject("Manager");
						Manager.transform.position = position2;
					}
					val8.SetParent(tempParent, true);
					val8.voxel = val3;
					if ((Object)(object)val3.staticProxy == (Object)null)
					{
						val3.staticProxy = val8;
					}
					SetProxyColorAndOrientation(val8, stain.Color, ((RaycastHit)(ref val6)).normal, stain.Size);
					MonoSingleton<StainVoxelManager>.Instance.AcknowledgeNewStain(val3);
					CustomStain customStain = new CustomStain(position, stain.Color, stain.Offset, stain.Size, val7.transform, val7.transform.localPosition, normal);
					paints.Add(customStain);
					return customStain;
				}
				Debug.Log((object)"Raycast did not hit any object.");
				return null;
			}
			((BaseUnityPlugin)this).Logger.LogWarning((object)"Failed to create voxel");
			return null;
		}

		private void Draw()
		{
			//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_0033: 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_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_0083: 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_0090: 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_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ad: Unknown result type (might be due to invalid IL or missing references)
			Camera main = Camera.main;
			if ((Object)(object)main == (Object)null)
			{
				return;
			}
			Ray val = main.ViewportPointToRay(new Vector3(0.5f, 0.5f, 0f));
			int num = 16777472;
			RaycastHit val2 = default(RaycastHit);
			if (!Physics.Raycast(val, ref val2, 100f, num))
			{
				return;
			}
			Vector3 point = ((RaycastHit)(ref val2)).point;
			Vector3 normal = ((RaycastHit)(ref val2)).normal;
			switch (tool)
			{
			case Tool.Brush:
				DrawPlane(point, normal);
				break;
			case Tool.Eraser:
				Erase(point);
				break;
			case Tool.Bucket:
				if (Input.GetMouseButtonDown(0))
				{
					PaintBucket(point, normal, currentColor);
				}
				break;
			}
		}

		private void Erase(Vector3 pos)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			List<CustomStain> list = FindVoxelAtPosition(pos, brushSize / 2.75f);
			if (list == null || list.Count <= 0)
			{
				return;
			}
			foreach (CustomStain item in list)
			{
				paints.Remove(item);
				Object.Destroy((Object)(object)((Component)item.Transform).gameObject);
			}
		}

		private CustomStain FindStain(Transform voxel)
		{
			return paints.Find((CustomStain x) => (Object)(object)x.Transform == (Object)(object)voxel);
		}

		public void PaintBucket(Vector3 startPosition, Vector3 normal, Color newColor)
		{
			//IL_0002: 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_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0064: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			Transform val = FindClosestVoxel(startPosition);
			if ((Object)(object)val == (Object)null)
			{
				return;
			}
			Color color = ((Component)val).GetComponent<Renderer>().material.color;
			List<Transform> list = new List<Transform>();
			Queue<Transform> queue = new Queue<Transform>();
			queue.Enqueue(val);
			while (queue.Count > 0)
			{
				Transform val2 = queue.Dequeue();
				if (list.Contains(val2) || !(((Component)val2).GetComponent<Renderer>().material.color == color))
				{
					continue;
				}
				list.Add(val2);
				List<CustomStain> list2 = FindVoxelAtPosition(val2.position, 0.1f, val2);
				foreach (CustomStain item in list2)
				{
					queue.Enqueue(item.Transform);
				}
			}
			foreach (Transform item2 in list)
			{
				((Component)item2).GetComponent<Renderer>().material.color = newColor;
			}
		}

		private Transform FindClosestVoxel(Vector3 position)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			return paints.OrderBy((CustomStain t) => Vector3.Distance(t.Position, position)).FirstOrDefault().Transform;
		}

		private List<CustomStain> FindVoxelAtPosition(Vector3 pos, float minDistance, Transform voxelToExclude = null)
		{
			//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)
			return paints.Where((CustomStain x) => (Object)(object)x.Transform != (Object)(object)voxelToExclude && Vector3.Distance(x.Position, pos) <= minDistance).ToList();
		}

		private void DrawPlane(Vector3 position, Vector3 normal)
		{
			//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_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003b: Expected O, but got Unknown
			//IL_004a: 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_007c: Expected O, but got Unknown
			//IL_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: 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_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0119: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position2 = position;
			position += normal * paintOffset;
			StainVoxel val = MonoSingleton<StainVoxelManager>.Instance.CreateOrGetVoxel(position, false);
			if (val != null)
			{
				GameObject val2 = new GameObject("ColoredVoxelProxy");
				val2.layer = 24;
				val2.transform.position = position;
				VoxelProxy val3 = val2.AddComponent<VoxelProxy>();
				if ((Object)(object)Manager == (Object)null)
				{
					Manager = new GameObject("Manager");
					Manager.transform.position = position2;
				}
				val3.SetParent(Manager.transform, true);
				val3.voxel = val;
				if ((Object)(object)val.staticProxy == (Object)null)
				{
					val.staticProxy = val3;
				}
				SetProxyColorAndOrientation(val3, currentColor, normal, brushSize / 2.75f);
				MonoSingleton<StainVoxelManager>.Instance.AcknowledgeNewStain(val);
				CustomStain item = new CustomStain(position, currentColor, paintOffset, brushSize / 2.75f, val2.transform, val2.transform.localPosition, normal);
				paints.Add(item);
			}
			else
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)"Failed to create voxel");
			}
		}

		private void SetProxyColorAndOrientation(VoxelProxy proxy, Color color, Vector3 normal, float scaleFactor)
		{
			//IL_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0095: Unknown result type (might be due to invalid IL or missing references)
			//IL_009a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			Material material = new Material(Shader.Find("Standard"))
			{
				color = color
			};
			MeshRenderer val = ((Component)proxy).gameObject.GetComponent<MeshRenderer>();
			if ((Object)(object)val == (Object)null)
			{
				val = ((Component)proxy).gameObject.AddComponent<MeshRenderer>();
			}
			((Renderer)val).material = material;
			MeshFilter component = ((Component)proxy).gameObject.GetComponent<MeshFilter>();
			if ((Object)(object)component == (Object)null)
			{
				component = ((Component)proxy).gameObject.AddComponent<MeshFilter>();
				component.mesh = CreatePlaneMesh();
			}
			((Component)proxy).transform.rotation = Quaternion.LookRotation(normal) * Quaternion.Euler(90f, 0f, 0f);
			((Component)proxy).transform.localScale = new Vector3(scaleFactor, 1f, scaleFactor);
		}

		private Mesh CreatePlaneMesh()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_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_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cf: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00db: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: 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)
			//IL_0124: 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_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0150: Unknown result type (might be due to invalid IL or missing references)
			Mesh val = new Mesh();
			float num = 1f;
			Vector3[] vertices = (Vector3[])(object)new Vector3[4]
			{
				new Vector3((0f - num) / 2f, 0f, (0f - num) / 2f),
				new Vector3(num / 2f, 0f, (0f - num) / 2f),
				new Vector3((0f - num) / 2f, 0f, num / 2f),
				new Vector3(num / 2f, 0f, num / 2f)
			};
			val.vertices = vertices;
			int[] triangles = new int[6] { 0, 2, 1, 2, 3, 1 };
			val.triangles = triangles;
			Vector3[] normals = (Vector3[])(object)new Vector3[4]
			{
				Vector3.up,
				Vector3.up,
				Vector3.up,
				Vector3.up
			};
			val.normals = normals;
			Vector2[] uv = (Vector2[])(object)new Vector2[4]
			{
				new Vector2(0f, 0f),
				new Vector2(1f, 0f),
				new Vector2(0f, 1f),
				new Vector2(1f, 1f)
			};
			val.uv = uv;
			return val;
		}
	}
}
namespace Paint.Utils
{
	internal static class ModUtils
	{
		public static Transform GetPlayerTransform()
		{
			return ((Component)MonoSingleton<NewMovement>.Instance).transform;
		}
	}
}
namespace Paint.Properties
{
	[CompilerGenerated]
	[GeneratedCode("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.5.0.0")]
	internal sealed class Settings : ApplicationSettingsBase
	{
		private static Settings defaultInstance = (Settings)(object)SettingsBase.Synchronized((SettingsBase)(object)new Settings());

		public static Settings Default => defaultInstance;
	}
}
namespace Paint.MonoBehaviours
{
	internal class PaintComponent : MonoBehaviour
	{
		public void Awake()
		{
		}

		public void Start()
		{
		}

		public void Update()
		{
		}

		public void LateUpdate()
		{
		}
	}
	internal class Settings : MonoBehaviour
	{
		private PaintPlugin plugin = PaintPlugin.Instance;

		public Text rField;

		public Text gField;

		public Text bField;

		public Text OffsetField;

		public Image image;

		public void SetR(float r)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Color color = ((Graphic)image).color;
			color.r = r / 255f;
			((Graphic)image).color = color;
			rField.text = r.ToString();
			plugin.currentColor = color;
		}

		public void SetG(float g)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Color color = ((Graphic)image).color;
			color.g = g / 255f;
			((Graphic)image).color = color;
			gField.text = g.ToString();
			plugin.currentColor = color;
		}

		public void SetB(float b)
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Unknown result type (might be due to invalid IL or missing references)
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			Color color = ((Graphic)image).color;
			color.b = b / 255f;
			((Graphic)image).color = color;
			bField.text = b.ToString();
			plugin.currentColor = color;
		}

		public void SetSize(float size)
		{
			plugin.brushSize = size;
		}

		public void SetOffset(float offset)
		{
			float paintOffset = Mathf.Round(offset / 0.01f) * 0.01f;
			plugin.paintOffset = paintOffset;
			OffsetField.text = paintOffset.ToString();
		}

		public void DeleteAllPaints()
		{
			PaintPlugin.RemoveAllPaints();
		}
	}
}