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.Singletons; using Bounce.Unmanaged; using DataModel; using HarmonyLib; using Photon; using PluginUtilities; 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("2.5.0.0")] [assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")] [assembly: AssemblyVersion("2.5.0.0")] namespace RPCPlugin { [BepInPlugin("org.hollofox.plugins.rpc", "RPC Plug-In", "2.5.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class RPCPlugin : DependencyUnityPlugin { public const string Name = "RPC Plug-In"; public const string Guid = "org.hollofox.plugins.rpc"; public const string Version = "2.5.0.0"; internal static ManualLogSource InternalLogger; internal static Harmony harmony; private bool _registerSingletons = true; protected override void OnAwake() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002a: Expected O, but got Unknown InternalLogger = ((BaseUnityPlugin)this).Logger; ((BaseUnityPlugin)this).Logger.LogInfo((object)"In Awake for RPC Plug-In"); harmony = new Harmony("org.hollofox.plugins.rpc"); harmony.PatchAll(); } protected override void OnDestroyed() { InternalLogger = null; try { RPCInstance.Destroy(); } catch { } Harmony obj2 = harmony; if (obj2 != null) { obj2.UnpatchSelf(); } harmony = null; InternalLogger = null; ((BaseUnityPlugin)this).Logger.LogDebug((object)"RPC Plug-In unloaded"); } 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> Handlers = new Dictionary>(); internal static RPCInstance Instance; internal static PhotonView View; internal static Dictionary Binaries = new Dictionary(); internal static Dictionary Ids = new Dictionary(); 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(new GameObject()); Instance = obj.AddComponent(); View = obj.AddComponent(); View.viewID = 606; } } public static void Destroy() { if (!((Object)(object)Instance != (Object)null)) { Object.Destroy((Object)(object)((Component)Instance).gameObject); Instance = null; View = null; Handlers.Clear(); } } public unsafe static void SendMessage(string message, NGuid thingThatIsTalking) { //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0025: 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) //IL_0039: 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_0065: 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_00b1: 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_0083: Unknown result type (might be due to invalid IL or missing references) //IL_0061: 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) RPCPlugin.InternalLogger.LogDebug((object)$"message: {message}, thingThatIsTalking: {thingThatIsTalking}"); PhotonView view = View; SourceRole val = (SourceRole)888; PlayerInfo value; CreatureBoardAsset val2 = default(CreatureBoardAsset); HideVolume val3 = default(HideVolume); if (message.Contains("ANONYMOUS", StringComparison.OrdinalIgnoreCase)) { val = (SourceRole)999; } else if (CampaignSessionManager.PlayersInfo.TryGetValue(new PlayerGuid(thingThatIsTalking), out value)) { val = (SourceRole)(!value.Rights.CanGm); } else if (CreaturePresenter.TryGetAsset(new CreatureGuid(thingThatIsTalking), ref val2)) { val = (SourceRole)2; } else if (SimpleSingletonBehaviour.HasInstance && SimpleSingletonBehaviour.Instance.TryGetHideVolumeData(thingThatIsTalking, ref val3)) { val = (SourceRole)3; } view.RPC("ReceivedMessage", (PhotonTargets)0, new object[3] { message, ((object)(*(NGuid*)(&thingThatIsTalking))/*cast due to .constrained prefix*/).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> 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 = (PhotonTargets)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 callback) { RPCInstance.Handlers.Add(key, callback); } public static void RemoveHandler(string key) { RPCInstance.Handlers.Remove(key); } public unsafe 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*)(&source))/*cast due to .constrained prefix*/).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.Interfaces { public abstract class RpcConsumer : IBinaryFactory where T : RpcMessage, new() { private static readonly Lazy> Lazy = new Lazy>(() => Activator.CreateInstance(typeof(RpcConsumer), nonPublic: true) as RpcConsumer); public static RpcConsumer 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 = (PhotonTargets)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); } } } } }