Decompiled source of MapImageObjects v1.2.3

MapImageObjects.dll

Decompiled 10 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading.Tasks;
using BepInEx;
using HarmonyLib;
using MapImageObjects.Core.Components;
using MapImageObjects.Core.Properties;
using MapsExt;
using MapsExt.MapObjects;
using MapsExt.Properties;
using Microsoft.CodeAnalysis;
using UnboundLib;
using UnityEngine;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("MapImageObjects")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Adds compatability for web image map objects!")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+219b2d16f0660971686344513a60057f0b44a308")]
[assembly: AssemblyProduct("MapImageObjects")]
[assembly: AssemblyTitle("MapImageObjects")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace MapImageObjects
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "MapImageObjects";

		public const string PLUGIN_NAME = "MapImageObjects";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MapImageObjects.Core
{
	public class ImageBackgroundObjectData : ImageObjectData
	{
	}
	public class ImageDestructibleObjectData : ImageObjectData
	{
		public DamageableProperty DamageableProperty = new DamageableProperty();
	}
	public class ImageDynamicObjectData : ImageObjectData
	{
	}
	public class ImageObjectData : MapObjectData
	{
		public PositionProperty position = new PositionProperty();

		public ScaleProperty scale = new ScaleProperty();

		public RotationProperty rotation = new RotationProperty();

		public AnimationProperty animation = new AnimationProperty();

		public ColorProperty color = new ColorProperty();

		public URIProperty uri = new URIProperty();
	}
	[MapObject(typeof(ImageBackgroundObjectData))]
	public class ImageBackgroundObject : ImageObject
	{
		public override void OnInstantiate(GameObject instance)
		{
			Object.Destroy((Object)(object)instance.GetComponent<Collider2D>());
			Object.Destroy((Object)(object)instance.GetComponent<SFPolygon>());
			DelayResetNetworkPhysics(instance);
			ImageObject.LateLoad<SpriteMask>(instance);
		}
	}
	[MapObject(typeof(ImageDestructibleObjectData))]
	public class ImageDestructibleObject : ImageObject
	{
		public override GameObject Prefab => MapObjectManager.LoadCustomAsset<GameObject>("Box Destructible");

		public override void OnInstantiate(GameObject instance)
		{
			//IL_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Expected O, but got Unknown
			Object.Destroy((Object)(object)((Component)instance.transform.GetChild(0)).gameObject);
			Object.Destroy((Object)(object)instance.GetComponent<Collider2D>());
			instance.AddComponent<PolygonCollider2D>();
			DelayResetNetworkPhysics(instance);
			SpriteRenderer component = instance.GetComponent<SpriteRenderer>();
			((Renderer)component).enabled = true;
			((Renderer)component).material = new Material(Shader.Find("Sprites/Default"));
			ExtensionMethods.GetOrAddComponent<ColorComponent>(instance, false).ApplyColor();
		}
	}
	[MapObject(typeof(ImageDynamicObjectData))]
	public class ImageDynamicObject : ImageObject
	{
		public override GameObject Prefab => MapObjectManager.LoadCustomAsset<GameObject>("Box");

		public override void OnInstantiate(GameObject instance)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			Object.Destroy((Object)(object)instance.GetComponent<Collider2D>());
			instance.AddComponent<PolygonCollider2D>();
			SpriteRenderer component = instance.GetComponent<SpriteRenderer>();
			((Renderer)component).enabled = true;
			((Renderer)component).material = new Material(Shader.Find("Sprites/Default"));
			Object.Destroy((Object)(object)((Component)instance.transform.GetChild(0)).gameObject);
			Object.Destroy((Object)(object)((Component)instance.transform.GetChild(1)).gameObject);
			ExtensionMethods.GetOrAddComponent<ColorComponent>(instance, false).ApplyColor();
			DelayResetNetworkPhysics(instance);
		}
	}
	[MapObject(typeof(ImageObjectData))]
	public class ImageObject : IMapObject
	{
		public virtual GameObject Prefab => MapObjectManager.LoadCustomAsset<GameObject>("Ground");

		public virtual void OnInstantiate(GameObject instance)
		{
			Object.Destroy((Object)(object)instance.GetComponent<Collider2D>());
			instance.AddComponent<PolygonCollider2D>();
			DelayResetNetworkPhysics(instance);
			ImageObject.LateLoad<SpriteMask>(instance);
		}

		public static async void LateLoad<ComponentType>(GameObject instance) where ComponentType : Component
		{
			while ((Object)(object)instance.GetComponent<ComponentType>() == (Object)null)
			{
				await Task.Delay(33);
			}
			Object.Destroy((Object)(object)instance.GetComponent<ComponentType>());
			SpriteRenderer orAddComponent = ExtensionMethods.GetOrAddComponent<SpriteRenderer>(instance, false);
			((Renderer)orAddComponent).material = new Material(Shader.Find("Sprites/Default"));
			if (!Object.op_Implicit((Object)(object)instance.GetComponent<PolygonCollider2D>()))
			{
				((Renderer)orAddComponent).sortingLayerName = "Background";
			}
			ExtensionMethods.GetOrAddComponent<ColorComponent>(instance, false).ApplyColor();
			URIComponent component = instance.GetComponent<URIComponent>();
			if ((Object)(object)component != (Object)null)
			{
				component.SetURI(component.GetURI());
			}
		}

		public async void DelayResetNetworkPhysics(GameObject instance)
		{
			await Task.Delay(1000);
			instance.GetComponent<NetworkPhysicsObject>().Awake();
		}
	}
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("com.woukie.rounds.mapimageobjects", "MapImageObjects", "1.2.3")]
	[BepInProcess("Rounds.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public static Dictionary<string, Sprite> ImageCache = new Dictionary<string, Sprite>();

		private void Awake()
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			new Harmony("com.woukie.rounds.mapimageobjects").PatchAll();
		}
	}
}
namespace MapImageObjects.Core.Properties
{
	public class ColorProperty : ValueProperty<Color>, ILinearProperty<ColorProperty>, ILinearProperty, IProperty
	{
		public static Color32 defaultColor = new Color32((byte)200, (byte)200, (byte)200, byte.MaxValue);

		[SerializeField]
		private readonly int _r;

		[SerializeField]
		private readonly int _g;

		[SerializeField]
		private readonly int _b;

		[SerializeField]
		private readonly int _a;

		public override Color Value => Color32.op_Implicit(new Color32((byte)_r, (byte)_g, (byte)_b, (byte)_a));

		public ColorProperty()
			: this(defaultColor)
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)


		public ColorProperty(Color color)
			: this(Mathf.RoundToInt(color.r * 255f), Mathf.RoundToInt(color.g * 255f), Mathf.RoundToInt(color.b * 255f), Mathf.RoundToInt(color.a * 255f))
		{
		}//IL_0001: 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_0023: 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)


		public ColorProperty(Color32 color)
			: this(color.r, color.g, color.b, color.a)
		{
		}//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)


		public ColorProperty(int r, int g, int b, int a)
		{
			_r = r;
			_g = g;
			_b = b;
			_a = a;
		}

		public static implicit operator Color(ColorProperty prop)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return ((ValueProperty<Color>)prop).Value;
		}

		public static implicit operator Color32(ColorProperty prop)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return Color32.op_Implicit(((ValueProperty<Color>)prop).Value);
		}

		public static implicit operator ColorProperty(Color color)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return new ColorProperty(color);
		}

		public static implicit operator ColorProperty(Color32 color32)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			return new ColorProperty(color32);
		}

		public ColorProperty Lerp(ColorProperty end, float t)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			return Color.Lerp((Color)this, (Color)end, t);
		}

		public IProperty Lerp(IProperty end, float t)
		{
			return (IProperty)(object)Lerp((ColorProperty)(object)end, t);
		}
	}
	[PropertySerializer(typeof(ColorProperty))]
	public class ColorPropertySerializer : IPropertyWriter<ColorProperty>
	{
		public void WriteProperty(ColorProperty property, GameObject target)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			ExtensionMethods.GetOrAddComponent<ColorComponent>(target, false).SetColor(property);
		}
	}
	public class URIProperty : IProperty
	{
		public string uri = "https://raw.githubusercontent.com/Woukie/Image/main/cover%20transparent.png";
	}
	[PropertySerializer(typeof(URIProperty))]
	public class URIPropertySerializer : IPropertyWriter<URIProperty>
	{
		public virtual void WriteProperty(URIProperty property, GameObject target)
		{
			ExtensionMethods.GetOrAddComponent<URIComponent>(target, false).SetURI(property.uri);
		}
	}
}
namespace MapImageObjects.Core.Components
{
	public class ColorComponent : MonoBehaviour
	{
		public Color color = Color.white;

		public Color GetColor()
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			return color;
		}

		public void SetColor(Color color)
		{
			//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)
			this.color = color;
			ApplyColor();
		}

		public void ApplyColor()
		{
			//IL_000f: 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: Unknown result type (might be due to invalid IL or missing references)
			SpriteRenderer[] componentsInChildren = ((Component)this).GetComponentsInChildren<SpriteRenderer>();
			for (int i = 0; i < componentsInChildren.Length; i++)
			{
				componentsInChildren[i].color = color;
			}
			LineRenderer[] componentsInChildren2 = ((Component)this).GetComponentsInChildren<LineRenderer>();
			foreach (LineRenderer obj in componentsInChildren2)
			{
				obj.startColor = color;
				obj.endColor = color;
			}
		}
	}
	public class URIComponent : MonoBehaviour
	{
		private string uri;

		public string GetURI()
		{
			return uri;
		}

		public void SetURI(string uri)
		{
			this.uri = uri;
			((MonoBehaviour)this).StopAllCoroutines();
			((MonoBehaviour)this).StartCoroutine(LoadImageCoroutine());
		}

		private IEnumerator LoadImageCoroutine()
		{
			Sprite value = null;
			if (Plugin.ImageCache.TryGetValue(uri, out value))
			{
				UpdateWithSprite(value);
				yield break;
			}
			UnityWebRequest www = UnityWebRequestTexture.GetTexture(GetURI());
			Texture2D content;
			try
			{
				UnityWebRequestAsyncOperation asyncOp = www.SendWebRequest();
				while (!((AsyncOperation)asyncOp).isDone)
				{
					yield return null;
				}
				if (www.isNetworkError || www.isHttpError)
				{
					yield break;
				}
				content = DownloadHandlerTexture.GetContent(www);
				((Texture)content).filterMode = (FilterMode)0;
			}
			finally
			{
				((IDisposable)www)?.Dispose();
			}
			if ((Object)(object)content != (Object)null)
			{
				value = Sprite.Create(content, new Rect(0f, 0f, (float)((Texture)content).width, (float)((Texture)content).height), new Vector2(0.5f, 0.5f), (float)((Texture)content).height);
				Plugin.ImageCache[uri] = value;
				UpdateWithSprite(value);
			}
		}

		private void UpdateWithSprite(Sprite sprite)
		{
			try
			{
				ExtensionMethods.GetOrAddComponent<SpriteRenderer>(((Component)this).gameObject, false).sprite = sprite;
				if (Object.op_Implicit((Object)(object)((Component)this).gameObject.GetComponent<PolygonCollider2D>()) && Object.op_Implicit((Object)(object)((Component)this).gameObject.GetComponent<SFPolygon>()))
				{
					Object.Destroy((Object)(object)((Component)this).gameObject.GetComponent<PolygonCollider2D>());
					Object.Destroy((Object)(object)((Component)this).gameObject.GetComponent<SFPolygon>());
					PolygonCollider2D val = ((Component)this).gameObject.AddComponent<PolygonCollider2D>();
					SFPolygon val2 = ((Component)this).gameObject.AddComponent<SFPolygon>();
					val2.pathCount = val.pathCount;
					for (int i = 0; i < val.pathCount; i++)
					{
						val2.SetPath(i, val.GetPath(i));
					}
				}
			}
			catch (Exception)
			{
			}
		}
	}
}