Decompiled source of EmailApi v0.0.5

EmailApi/EmailApi.dll

Decompiled 4 months ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using CommonAPI;
using HarmonyLib;
using Reptile;
using Reptile.Phone;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.6", FrameworkDisplayName = ".NET Framework 4.6")]
[assembly: AssemblyCompany("EmailApi")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("EmailApi")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("EmailApi")]
[assembly: AssemblyTitle("EmailApi")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
internal static class JsonUtilityEx
{
	[Serializable]
	private class Wrapper<T>
	{
		public T[] array;
	}

	public static T[] getJsonArray<T>(string json)
	{
		return JsonUtility.FromJson<Wrapper<T>>("{ \"array\": " + json + "}").array;
	}

	public static string arrayToJson<T>(T[] array)
	{
		return JsonUtility.ToJson((object)new Wrapper<T>
		{
			array = array
		});
	}
}
namespace MoveStyler.Utility
{
	public class TextureUtil
	{
		public static Texture2D GetTextureFromBitmap(Bitmap bitmap, FilterMode filterMode = 1)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Expected O, but got Unknown
			//IL_0027: 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_0033: Expected O, but got Unknown
			//IL_0034: 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: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Expected O, but got Unknown
			byte[] array = (byte[])((TypeConverter)new ImageConverter()).ConvertTo((object?)bitmap, typeof(byte[]));
			Texture2D val = new Texture2D(((Image)bitmap).Width, ((Image)bitmap).Height);
			ImageConversion.LoadImage(val, array);
			((Texture)val).filterMode = filterMode;
			val.Apply();
			return val;
		}
	}
}
namespace OutfitSwitcher
{
	public static class LoadUtil
	{
		public static readonly BindingFlags BindingFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic;

		public static Assets GetAssets(CharacterLoader instance)
		{
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			return (Assets)(((object)instance).GetType().GetField("assets", BindingFlags)?.GetValue(instance));
		}

		public static MethodInfo GetMethod(this object instance, string name)
		{
			return instance.GetType().GetMethod(name, BindingFlags);
		}

		public static void InvokeMethod(this object instance, string name, params object[] parameters)
		{
			Traverse.Create(instance).Method(name, parameters).GetValue(parameters);
		}

		public static void InvokeMethod(this object instance, string name, Type[] types, params object[] parameters)
		{
			Traverse.Create(instance).Method(name, types, (object[])null).GetValue(parameters);
		}

		public static FieldInfo GetField(this object instance, string name)
		{
			return instance.GetType().GetField(name, BindingFlags);
		}

		public static T GetComponentValue<T>(this object instance, string name) where T : Component
		{
			object? value = instance.GetField(name).GetValue(instance);
			return (T)((value is T) ? value : null);
		}

		public static T GetFieldValue<T>(this object instance, string name) where T : class
		{
			return instance.GetField(name).GetValue(instance) as T;
		}

		public static void SetField(this object instance, string name, object value)
		{
			instance.GetField(name).SetValue(instance, value);
		}
	}
}
namespace RabbitMS.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	public class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		public static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					resourceMan = new ResourceManager("RabbitMS.Properties.Resources", typeof(Resources).Assembly);
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		public static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		public static Bitmap logo_background => (Bitmap)ResourceManager.GetObject("logo_background", resourceCulture);

		public static Bitmap phoneAppIcon => (Bitmap)ResourceManager.GetObject("phoneAppIcon", resourceCulture);

		internal Resources()
		{
		}
	}
}
namespace EmailApi
{
	public static class EmailManager
	{
		private static ManualLogSource DebugLog = Logger.CreateLogSource("EmailApi EmailManager");

		private static int msgSenderID = 9001;

		private static Color msgSenderColor = new Color(1f, 0.9f, 0.9f);

		public static EmailMessage msg_tutorial;

		public static Color[] msgSenderColors = (Color[])(object)new Color[2]
		{
			new Color(1f, 1f, 1f, 1f),
			new Color(0.4863f, 0.5569f, 0.78f, 1f)
		};

		public static Color[] msgSubjectColors = (Color[])(object)new Color[2]
		{
			new Color(0.196f, 0.31f, 0.612f, 1f),
			new Color(1f, 1f, 1f, 1f)
		};

		public static Player player;

		public static Phone phone;

		public static AppEmail emailApp;

		public static List<KeyValuePair<EmailMessage, bool>> _messagesDatabase;

		public static Dictionary<string, EmailMessage> _messagesIDDatabase;

		private static EmailSave SaveState;

		private static EmailApiPlugin plugin;

		public static Dictionary<int, CustomContact> _Contacts { get; private set; }

		public static void Initialize(EmailApiPlugin _plugin)
		{
			DebugLog.LogMessage((object)"Init Email Manager");
			plugin = _plugin;
			InitLoadEmailSave();
			InitCustomContacts();
			InitEmailMessages();
		}

		private static void InitLoadEmailSave()
		{
			new EmailSave();
			_ = EmailSave.Instance.hasReadData;
		}

		private static void InitCustomContacts()
		{
			_Contacts = new Dictionary<int, CustomContact>();
		}

		public static CustomContact RegisterCustomContact(string contactName, int contactID, Texture2D contactImage)
		{
			CustomContact customContact = new CustomContact(contactID, contactName);
			customContact.avatar = TextureUtility.CreateSpriteFromTexture(contactImage);
			_Contacts.Add(customContact.characterID, customContact);
			DebugLog.LogMessage((object)("Added Contact " + contactName));
			return customContact;
		}

		private static void InitEmailMessages()
		{
			_messagesDatabase = new List<KeyValuePair<EmailMessage, bool>>();
			_messagesIDDatabase = new Dictionary<string, EmailMessage>();
		}

		public static void AddEmailMessage(EmailMessage email, bool checkSave = false)
		{
			_messagesDatabase.Add(new KeyValuePair<EmailMessage, bool>(email, checkSave));
			_messagesIDDatabase.Add(((Object)email).name, email);
		}

		public static EmailMessage CreateEmailMessage(string msgID, int msgSenderID, string subject, Color msgSenderColor, List<string> messages)
		{
			//IL_001b: 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)
			EmailMessage obj = ScriptableObject.CreateInstance<EmailMessage>();
			((Object)obj).name = msgID;
			obj.characterNameIDOfSender = msgSenderID;
			obj.subject = subject;
			obj.profileBackground = msgSenderColor;
			obj.message = messages.ToArray();
			return obj;
		}

		public static void EmailNotification(string MessageID, bool setSave = true)
		{
			player = WorldHandler.instance.GetCurrentPlayer();
			phone = player.phone;
			emailApp = phone.GetAppInstance<AppEmail>();
			if (!((Object)(object)emailApp != (Object)null))
			{
				return;
			}
			if (_messagesIDDatabase.TryGetValue(MessageID, out var value))
			{
				if (setSave)
				{
					EmailSave.Instance.setMessageState(MessageID, setSave);
				}
				emailApp.PushNotification(value);
			}
			else
			{
				DebugLog.LogMessage((object)("Failed to find email of ID: " + MessageID));
			}
		}

		public static void EmailNotificationDelayed(string MessageID, bool setSave = true, float delay = 2f)
		{
			plugin.DelayEmailNotification(MessageID, setSave, delay);
		}
	}
	public struct CustomContact
	{
		public int characterID;

		public string characterName;

		public Sprite avatar;

		public Guid associatedCharacterGuid;

		public int CompareTo(Contact other)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			return characterID.CompareTo(other.characterID);
		}

		public CustomContact(int characterID, string characterName)
		{
			this.characterID = characterID;
			this.characterName = characterName;
			avatar = null;
			associatedCharacterGuid = Guid.Empty;
		}
	}
	[HarmonyPatch(typeof(AppEmail))]
	public class PhoneAppEmailPatch
	{
		private static ManualLogSource DebugLog = Logger.CreateLogSource("EmailApi AppEmail Patch");

		[HarmonyPostfix]
		[HarmonyPatch("RefreshList")]
		public static void RefreshListpatch(AppEmail __instance, ref List<EmailMessage> ___m_Emails, ref EmailScrollView ___m_CardsScroll)
		{
			___m_Emails.Reverse();
			foreach (KeyValuePair<EmailMessage, bool> item in EmailManager._messagesDatabase)
			{
				if ((EmailSave.Instance.getMessageState(((Object)item.Key).name) || !item.Value) && !___m_Emails.Contains(item.Key))
				{
					___m_Emails.Add(item.Key);
				}
			}
			___m_Emails.Reverse();
			((PhoneScroll)___m_CardsScroll).UpdateListContent(___m_Emails.Count);
		}

		[HarmonyPrefix]
		[HarmonyPatch("PushNotification")]
		public static bool PushNotificationPatch(AppEmail __instance, EmailMessage email)
		{
			if (email.characterNameIDOfSender > 9000)
			{
				if (EmailManager._Contacts.TryGetValue(email.characterNameIDOfSender, out var value))
				{
					EmailManager.phone.PushNotification((App)(object)__instance, value.characterName, (AUnlockable)(object)email);
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(EmailCard))]
	public class EmailCardPatch
	{
		private static ManualLogSource DebugLog = Logger.CreateLogSource("EmailApi EmailCard");

		[HarmonyPrefix]
		[HarmonyPatch("SetContent")]
		public static bool SetContentpatch(EmailCard __instance, AUnlockable content, ref Image ___m_ProfilePicture, ref Image ___m_BackgroundImage)
		{
			EmailMessage val = (EmailMessage)(object)((content is EmailMessage) ? content : null);
			if ((Object)(object)val != (Object)null && val.characterNameIDOfSender > 9000)
			{
				PropertyInfo property = typeof(EmailCard).GetProperty("AssignedContent", BindingFlags.Instance | BindingFlags.Public);
				property = property.DeclaringType.GetProperty(property.Name);
				property.SetValue(__instance, content);
				TextMeshProUGUI subjectLabel = __instance.m_SubjectLabel;
				TextMeshProUGUI senderLabel = __instance.m_SenderLabel;
				((TMP_Text)subjectLabel).text = val.subject;
				string text = val.characterNameIDOfSender.ToString();
				if (EmailManager._Contacts.TryGetValue(val.characterNameIDOfSender, out var value))
				{
					text = value.characterName;
					___m_ProfilePicture.sprite = value.avatar;
					__instance.m_SenderColors = EmailManager.msgSenderColors;
					__instance.m_SubjectColors = EmailManager.msgSubjectColors;
				}
				((TMP_Text)senderLabel).text = text;
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(EmailMessagePanel))]
	internal class EmailMessagePanelPatch
	{
		private static ManualLogSource DebugLog = Logger.CreateLogSource("EmailApi EmailCard");

		[HarmonyPrefix]
		[HarmonyPatch("SetContent")]
		public static bool SetContentpatch(EmailMessagePanel __instance, EmailMessage email, ref int ___messageCurrentPage, ref int ___messagePageCount, ref EmailMessage ___currentEmail, ref TextMeshProUGUI ___senderText, ref TextMeshProUGUI ___subjectText, ref TextMeshProUGUI ___messageArea, ref Image ___senderAvatar)
		{
			if (email.characterNameIDOfSender > 9000)
			{
				___messageCurrentPage = 0;
				___messagePageCount = email.message.Length;
				___currentEmail = email;
				((TMP_Text)___senderText).text = email.characterNameIDOfSender.ToString();
				((TMP_Text)___subjectText).text = email.subject;
				if (EmailManager._Contacts.TryGetValue(email.characterNameIDOfSender, out var value))
				{
					((TMP_Text)___senderText).text = value.characterName;
					___senderAvatar.sprite = value.avatar;
				}
				((Component)___messageArea).gameObject.SetActive(false);
				return false;
			}
			return true;
		}
	}
	public class EmailSave : CustomSaveData
	{
		private static ManualLogSource DebugLog = Logger.CreateLogSource("EmailApi Email Manager Save");

		private readonly Dictionary<string, bool> messageStates;

		public bool hasReadData;

		public static EmailSave Instance { get; private set; }

		public EmailSave()
			: base("EmailApi", "{0}_msg.data", (SaveLocations)1)
		{
			Instance = this;
			messageStates = new Dictionary<string, bool>();
			DebugLog.LogMessage((object)"Start Email Save");
			DebugLog.LogMessage((object)base.Filename);
		}

		public void setMessageState(string messageName, bool state)
		{
			if (messageStates.ContainsKey(messageName))
			{
				messageStates[messageName] = state;
				((CustomSaveData)Instance).Save();
			}
			else
			{
				messageStates.Add(messageName, state);
				((CustomSaveData)Instance).Save();
			}
		}

		public bool getMessageState(string messageName)
		{
			if (messageStates.ContainsKey(messageName))
			{
				return messageStates[messageName];
			}
			return false;
		}

		public override void Initialize()
		{
			DebugLog.LogMessage((object)"EmailManager Init");
			messageStates.Clear();
		}

		public override void Read(BinaryReader reader)
		{
			reader.ReadByte();
			int num = reader.ReadInt32();
			for (int i = 0; i < num; i++)
			{
				string key = reader.ReadString();
				bool value = reader.ReadBoolean();
				if (!messageStates.ContainsKey(key))
				{
					messageStates.Add(key, value);
				}
			}
			hasReadData = true;
		}

		public override void Write(BinaryWriter writer)
		{
			writer.Write((byte)0);
			writer.Write(messageStates.Count);
			foreach (KeyValuePair<string, bool> messageState in messageStates)
			{
				writer.Write(messageState.Key);
				writer.Write(messageState.Value);
			}
		}
	}
	[BepInPlugin("EmailApi", "EmailApi", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class EmailApiPlugin : BaseUnityPlugin
	{
		public const string CharacterAPIGuid = "com.Viliger.CharacterAPI";

		private const string CommonAPIGUID = "CommonAPI";

		public EmailApiPlugin Instance;

		private static ManualLogSource DebugLog = Logger.CreateLogSource("EmailApi Plugin");

		private void Awake()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			((BaseUnityPlugin)this).Logger.LogMessage((object)"EmailApi v0.1.0 starting...");
			new Harmony("EmailApi").PatchAll();
			Instance = this;
			((BaseUnityPlugin)this).Logger.LogMessage((object)"Init Email Save");
			EmailManager.Initialize(this);
		}

		public void DelayEmailNotification(string messageID, bool save, float delay)
		{
			((MonoBehaviour)this).StartCoroutine(DelayEmailRoutine(messageID, save, delay));
		}

		private IEnumerator DelayEmailRoutine(string messageID, bool save, float delay)
		{
			yield return (object)new WaitForSeconds(delay);
			EmailManager.EmailNotification(messageID, save);
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "EmailApi";

		public const string PLUGIN_NAME = "EmailApi";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}