Decompiled source of RPChat v0.4.2

plugins\RPChat.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Jotunn;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("JotunnModStub")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JotunnModStub")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.6.2", FrameworkDisplayName = ".NET Framework 4.6.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace RPChat;

[BepInPlugin("org.bepinex.plugins.bid.rpchat", "RPChat", "0.4.2")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
internal class RPChat : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Player), "CanSwitchPVP")]
	private class Player_CanSwitchPVP_patch
	{
		private static bool Prefix(ref bool __result)
		{
			if (PVPConfig.Value)
			{
				__result = false;
				return false;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Player), "OnSpawned")]
	private class Player_OnSpawned_patch
	{
		private static void Postfix(Player __instance)
		{
			if (PVPConfig.Value)
			{
				__instance.SetPVP(true);
			}
		}
	}

	[HarmonyPatch(typeof(Player), "OnRespawn")]
	private class Player_OnRespawn_patch
	{
		private static void Postfix(Player __instance)
		{
			if (PVPConfig.Value)
			{
				__instance.SetPVP(true);
			}
		}
	}

	[HarmonyPatch(typeof(ZNet), "Awake")]
	private class ZNet_Awake_patch
	{
		private static void Postfix(ZNet __instance)
		{
			if (DontShowPlayersConfig.Value)
			{
				__instance.SetPublicReferencePosition(false);
			}
		}
	}

	[HarmonyPatch(typeof(ZNet), "SetPublicReferencePosition")]
	private class ZNet_SetPublicReferencePosition_patch
	{
		private static void Prefix(ref bool pub)
		{
			if (DontShowPlayersConfig.Value)
			{
				pub = false;
				if ((Object)(object)Minimap.instance != (Object)null && !Minimap.instance.m_publicPosition.isOn)
				{
					((Selectable)Minimap.instance.m_publicPosition).interactable = false;
				}
			}
			else
			{
				((Selectable)Minimap.instance.m_publicPosition).interactable = true;
			}
		}
	}

	[HarmonyPatch(typeof(ZNet), "IsReferencePositionPublic")]
	private class ZNet_IsReferencePositionPublic_patch
	{
		private static bool Prefix(ref bool __result)
		{
			if (DontShowPlayersConfig.Value)
			{
				__result = false;
				if ((Object)(object)Minimap.instance != (Object)null && ((Selectable)Minimap.instance.m_publicPosition).interactable)
				{
					((Selectable)Minimap.instance.m_publicPosition).interactable = false;
				}
				return false;
			}
			if ((Object)(object)Minimap.instance != (Object)null && !((Selectable)Minimap.instance.m_publicPosition).interactable)
			{
				((Selectable)Minimap.instance.m_publicPosition).interactable = true;
			}
			return true;
		}
	}

	[HarmonyPatch(typeof(Player), "SetPVP", new Type[] { typeof(bool) })]
	private class Player_SetPVP_patch
	{
		private static void Prefix(ref bool enabled, Player __instance)
		{
			if (PVPConfig.Value)
			{
				enabled = true;
				if ((Object)(object)InventoryGui.instance != (Object)null && !InventoryGui.instance.m_pvp.isOn)
				{
					InventoryGui.instance.m_pvp.isOn = true;
				}
			}
		}
	}

	[HarmonyPatch(typeof(Talker), "Awake")]
	private class Talker_Awake_patch
	{
		private static void Postfix(Talker __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				__instance.m_visperDistance = WhisperDistanceConfig.Value;
				__instance.m_normalDistance = SayDistanceConfig.Value;
				__instance.m_shoutDistance = ShoutDistanceConfig.Value;
			}
		}
	}

	[HarmonyPatch(typeof(Chat), "OnNewChatMessage", new Type[]
	{
		typeof(GameObject),
		typeof(long),
		typeof(Vector3),
		typeof(Type),
		typeof(UserInfo),
		typeof(string),
		typeof(string)
	})]
	private class Chat_OnNewChatMessage_patch
	{
		private static bool Prefix(GameObject go, long senderID, Vector3 pos, Type type, UserInfo user, string text, string senderNetworkUserId)
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Expected I4, but got Unknown
			//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_0065: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Invalid comparison between Unknown and I4
			//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: 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_0096: 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)
			if ((Object)(object)Player.m_localPlayer == (Object)null)
			{
				return true;
			}
			float num = 0f;
			switch ((int)type)
			{
			case 0:
				num = WhisperDistanceConfig.Value;
				break;
			case 1:
				num = SayDistanceConfig.Value;
				break;
			case 2:
				num = ShoutDistanceConfig.Value;
				break;
			case 3:
				num = SayDistanceConfig.Value;
				break;
			}
			Vector3 val = pos;
			if ((int)type == 3)
			{
				foreach (Player allPlayer in Player.GetAllPlayers())
				{
					ZDOID zDOID = ((Character)allPlayer).GetZDOID();
					if (((ZDOID)(ref zDOID)).UserID == senderID)
					{
						val = ((Component)allPlayer).transform.position;
					}
				}
			}
			if (Vector3.Distance(val, ((Component)Player.m_localPlayer).transform.position) < num)
			{
				return true;
			}
			return false;
		}
	}

	public const string PluginGUID = "org.bepinex.plugins.bid.rpchat";

	public const string PluginName = "RPChat";

	public const string PluginVersion = "0.4.2";

	public static ConfigEntry<int> WhisperDistanceConfig;

	public static ConfigEntry<int> SayDistanceConfig;

	public static ConfigEntry<int> ShoutDistanceConfig;

	public static ConfigEntry<bool> PVPConfig;

	public static ConfigEntry<bool> DontShowPlayersConfig;

	private readonly Harmony harmony = new Harmony("org.bepinex.plugins.bid.rpchat");

	public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

	private void Awake()
	{
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		Logger.LogInfo((object)"RPChat has landed");
		CreateConfigValues();
		new Harmony("org.bepinex.plugins.bid.rpchat").PatchAll();
		CreatureManager.OnVanillaCreaturesAvailable += ModifyAndCloneVanillaCreatures;
	}

	private void OnDestroy()
	{
		harmony.UnpatchSelf();
	}

	private void AddInputs()
	{
	}

	private void CreateConfigValues()
	{
		//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_0038: Expected O, but got Unknown
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		//IL_0042: Expected O, but got Unknown
		//IL_0067: 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_0074: Expected O, but got Unknown
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Expected O, but got Unknown
		//IL_00a3: 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_00b0: Expected O, but got Unknown
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ba: Expected O, but got Unknown
		//IL_00de: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
		//IL_00eb: Expected O, but got Unknown
		//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f5: Expected O, but got Unknown
		//IL_0119: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0126: Expected O, but got Unknown
		//IL_0126: Unknown result type (might be due to invalid IL or missing references)
		//IL_0130: Expected O, but got Unknown
		((BaseUnityPlugin)this).Config.SaveOnConfigSet = true;
		WhisperDistanceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Server config", "WhisperDistance", 4, new ConfigDescription("distance whispering can be heard", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		SayDistanceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Server config", "SayDistance", 15, new ConfigDescription("distance normal chats can be heard", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		ShoutDistanceConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Server config", "ShoutDistance", 70, new ConfigDescription("distance shouting can be heard", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		PVPConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Server config", "PVPOn", false, new ConfigDescription("force PVP on", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		DontShowPlayersConfig = ((BaseUnityPlugin)this).Config.Bind<bool>("Server config", "ForceShowPlayersOff", false, new ConfigDescription("force visibility of player off", (AcceptableValueBase)null, new object[1] { (object)new ConfigurationManagerAttributes
		{
			IsAdminOnly = true
		} }));
		SynchronizationManager.OnConfigurationSynchronized += delegate(object obj, ConfigurationSynchronizationEventArgs attr)
		{
			if (attr.InitialSynchronization)
			{
				Logger.LogMessage((object)"Initial Config sync event received");
			}
			else
			{
				Logger.LogMessage((object)"Config sync event received");
			}
		};
		if ((Object)(object)Player.m_localPlayer != (Object)null && PVPConfig.Value)
		{
			Player.m_localPlayer.SetPVP(PVPConfig.Value);
		}
		if ((Object)(object)ZNet.instance != (Object)null && DontShowPlayersConfig.Value)
		{
			ZNet.instance.SetPublicReferencePosition(false);
		}
	}

	private void Update()
	{
	}

	private void ModifyAndCloneVanillaCreatures()
	{
		CreatureManager.OnVanillaCreaturesAvailable -= ModifyAndCloneVanillaCreatures;
	}
}