Decompiled source of RPCPlugin v2.3.0

RPCPlugin.dll

Decompiled a day ago
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Cryptography;
using System.Text;
using BepInEx;
using BepInEx.Logging;
using Bounce.ManagedCollections;
using Bounce.Unmanaged;
using DataModel;
using HarmonyLib;
using Photon;
using RPCPlugin.Interfaces;
using RPCPlugin.RPC;
using Talespire;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("RPCPlugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("Hollo")]
[assembly: AssemblyProduct("RPCPlugin")]
[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 RPCPlugin
{
	[BepInPlugin("org.hollofox.plugins.rpc", "HolloFoxes' RPC Plug-In", "2.2.1.0")]
	public class RPCPlugin : BaseUnityPlugin
	{
		public const string Name = "HolloFoxes' RPC Plug-In";

		public const string Guid = "org.hollofox.plugins.rpc";

		public const string Version = "2.2.1.0";

		internal static ManualLogSource InternalLogger;

		private bool _registerSingletons = true;

		public void Awake()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			InternalLogger = ((BaseUnityPlugin)this).Logger;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"In Awake for HolloFoxes' RPC Plug-In");
			new Harmony("org.hollofox.plugins.rpc").PatchAll();
		}

		public void Update()
		{
			if (_registerSingletons)
			{
				InitOnLoad.Initialise();
				_registerSingletons = false;
			}
			if ((Object)(object)RPCInstance.Instance == (Object)null && PhotonNetwork.inRoom)
			{
				RPCInstance.Init();
			}
		}
	}
}
namespace RPCPlugin.RPC
{
	public sealed class RPCInstance : PunBehaviour
	{
		internal static Dictionary<string, Func<string, string, SourceRole, string>> Handlers = new Dictionary<string, Func<string, string, SourceRole, string>>();

		internal static RPCInstance Instance;

		internal static PhotonView View;

		internal static BList<HideVolumeItem> hideVolumes;

		internal static Dictionary<Guid, IBinaryFactory> Binaries = new Dictionary<Guid, IBinaryFactory>();

		internal static Dictionary<string, byte[]> Ids = new Dictionary<string, byte[]>();

		public static void Init()
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Expected O, but got Unknown
			if (!((Object)(object)Instance != (Object)null))
			{
				GameObject obj = Object.Instantiate<GameObject>(new GameObject());
				Instance = obj.AddComponent<RPCInstance>();
				View = obj.AddComponent<PhotonView>();
				View.viewID = 606;
			}
		}

		public static void SendMessage(string message, NGuid thingThatIsTalking)
		{
			//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)
			//IL_0019: 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_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_004b: 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_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d8: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0078: Unknown result type (might be due to invalid IL or missing references)
			RPCPlugin.InternalLogger.LogDebug((object)$"message: {message}, thingThatIsTalking: {thingThatIsTalking}");
			PhotonView view = View;
			SourceRole val = (SourceRole)888;
			PlayerInfo value;
			CreatureBoardAsset val2 = default(CreatureBoardAsset);
			if (message.Contains("ANONYMOUS", StringComparison.OrdinalIgnoreCase))
			{
				val = (SourceRole)999;
			}
			else if (CampaignSessionManager.PlayersInfo.TryGetValue(new PlayerGuid(thingThatIsTalking), out value))
			{
				val = (SourceRole)((!value.Rights.CanGm) ? 1 : 0);
			}
			else if (CreaturePresenter.TryGetAsset(new CreatureGuid(thingThatIsTalking), ref val2))
			{
				val = (SourceRole)2;
			}
			else if (hideVolumes.ToArray().Any((HideVolumeItem hv) => hv.HideVolume.Id == thingThatIsTalking))
			{
				val = (SourceRole)3;
			}
			view.RPC("ReceivedMessage", (PhotonTargets)0, new object[3]
			{
				message,
				((object)(NGuid)(ref thingThatIsTalking)).ToString(),
				val
			});
		}

		[PunRPC]
		public void ReceivedMessage(string message, string thingThatIsTalking, SourceRole chatSource)
		{
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			foreach (KeyValuePair<string, Func<string, string, SourceRole, string>> handler in Handlers)
			{
				RPCPlugin.InternalLogger.LogDebug((object)("RPC Plugin: ParseMessage: Found Handler '" + handler.Key + "'"));
				if (message.StartsWith(handler.Key))
				{
					RPCPlugin.InternalLogger.LogDebug((object)("RPC: ParseMessage: Applying Handler '" + handler.Key + "'"));
					try
					{
						message = handler.Value(message, thingThatIsTalking, chatSource);
					}
					catch (Exception ex)
					{
						RPCPlugin.InternalLogger.LogWarning((object)("RPC Plugin: ParseMessage: Exception In Handler: " + ex.Message));
						RPCPlugin.InternalLogger.LogError((object)ex);
						message = "";
					}
					RPCPlugin.InternalLogger.LogDebug((object)("RPC Plugin: ParseMessage: Post Handler: Title = '" + Convert.ToString(thingThatIsTalking) + "' Message = '" + Convert.ToString(message) + "'"));
					if (message != null && !(message.Trim() == ""))
					{
					}
					break;
				}
			}
		}

		public static void SendMessage(RpcMessage rpcMessage, PhotonTargets targets = 0)
		{
			//IL_000f: Unknown result type (might be due to invalid IL or missing references)
			PhotonView view = View;
			if (view != null)
			{
				view.RPC("ReceivedBinaryMessage", targets, new object[2]
				{
					rpcMessage.Id(),
					rpcMessage.Value()
				});
			}
		}

		[PunRPC]
		public void ReceivedBinaryMessage(byte[] bid, byte[] message)
		{
			Guid guid = new Guid(bid);
			if (!Binaries.ContainsKey(guid))
			{
				RPCPlugin.InternalLogger.LogDebug((object)$"RPC Key not found: {guid}");
			}
			else
			{
				Binaries[guid].Handle(message);
			}
		}
	}
	public static class RPCManager
	{
		public static void AddHandler(string key, Func<string, string, SourceRole, string> callback)
		{
			RPCInstance.Handlers.Add(key, callback);
		}

		public static void RemoveHandler(string key)
		{
			RPCInstance.Handlers.Remove(key);
		}

		public static void SendMessage(string message, NGuid source)
		{
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			RPCPlugin.InternalLogger.LogDebug((object)("RPCManager: Sending " + message + " (signature " + ((object)(NGuid)(ref source)).ToString() + ")"));
			RPCInstance.SendMessage(message, source);
		}
	}
}
namespace RPCPlugin.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

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

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

		internal Resources()
		{
		}
	}
}
namespace RPCPlugin.Patches
{
	[HarmonyPatch(typeof(HideVolumeManager), "OnHideVolumeAdded")]
	internal class HVMAddPatch
	{
		public static void Postfix(ref HideVolume volume, ref BList<HideVolumeItem> ____hideVolumeItems)
		{
			RPCInstance.hideVolumes = ____hideVolumeItems;
		}
	}
	[HarmonyPatch(typeof(HideVolumeManager), "OnHideVolumeRemoved")]
	internal class HVMRemovePatch
	{
		public static void Postfix(ref HideVolume volume, ref BList<HideVolumeItem> ____hideVolumeItems)
		{
			RPCInstance.hideVolumes = ____hideVolumeItems;
		}
	}
}
namespace RPCPlugin.Interfaces
{
	public abstract class RpcConsumer<T> : IBinaryFactory where T : RpcMessage, new()
	{
		private static readonly Lazy<RpcConsumer<T>> Lazy = new Lazy<RpcConsumer<T>>(() => Activator.CreateInstance(typeof(RpcConsumer<T>), nonPublic: true) as RpcConsumer<T>);

		public static RpcConsumer<T> Instance => Lazy.Value;

		public abstract void Handle(T message);

		public void Handle(byte[] data)
		{
			T message = (T)Activator.CreateInstance(typeof(T), data);
			Handle(message);
		}

		public virtual void SendMessage(T message, PhotonTargets targets = 0)
		{
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			RPCInstance.SendMessage(message, targets);
		}

		protected RpcConsumer()
		{
			string assemblyQualifiedName = typeof(T).AssemblyQualifiedName;
			Guid guid = new Guid(RpcMessage.CreateMD5(assemblyQualifiedName));
			RPCInstance.Binaries.Add(guid, this);
			RPCPlugin.InternalLogger.LogDebug((object)$"Registered assembly: {guid} {assemblyQualifiedName}");
		}
	}
	public abstract class RpcMessage : IBinaryMessage
	{
		public abstract byte[] Value();

		public byte[] Id()
		{
			string assemblyQualifiedName = GetType().AssemblyQualifiedName;
			if (!RPCInstance.Ids.ContainsKey(assemblyQualifiedName))
			{
				RPCInstance.Ids[assemblyQualifiedName] = CreateMD5(assemblyQualifiedName);
			}
			return RPCInstance.Ids[assemblyQualifiedName];
		}

		public static byte[] CreateMD5(string input)
		{
			using MD5 mD = MD5.Create();
			byte[] bytes = Encoding.ASCII.GetBytes(input);
			return mD.ComputeHash(bytes);
		}
	}
	public interface IBinaryMessage
	{
		byte[] Value();
	}
	public interface IBinaryFactory
	{
		void Handle(byte[] message);
	}
	public class InitOnLoad : Attribute
	{
		public static void Initialise()
		{
			foreach (Type type in from t in AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly a) => a.GetTypes())
				where t.GetCustomAttributes(typeof(InitOnLoad), inherit: false).Any()
				select t)
			{
				FieldInfo fieldInfo = type.GetFields(BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic).FirstOrDefault((FieldInfo f) => f.FieldType == type);
				if (fieldInfo != null)
				{
					fieldInfo.GetValue(null);
				}
			}
		}
	}
}

SourceRole.dll

Decompiled a day ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("SourceRole")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SourceRole")]
[assembly: AssemblyCopyright("Copyright ©  2022")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("08b45a92-bf19-40cb-9712-436e153d8fcf")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Talespire;

public enum SourceRole
{
	gm = 0,
	player = 1,
	creature = 2,
	hideVolume = 3,
	other = 888,
	anonymous = 999
}