Decompiled source of SocialSystemTweaks v1.0.0

Cjayride.SocialSystemTweaks.dll

Decompiled 19 hours ago
using System;
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 BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using SocialSystem.Client;
using SocialSystem.Core;
using SocialSystem.UI;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("assembly_valheim")]
[assembly: IgnoresAccessChecksTo("SocialSystem")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("Cjayride.SocialSystemTweaks")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Cjayride.SocialSystemTweaks")]
[assembly: AssemblyTitle("Cjayride.SocialSystemTweaks")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 Cjayride.SocialSystemTweaks
{
	[HarmonyPatch]
	[HarmonyPriority(0)]
	internal static class CombatInvites
	{
		private static readonly MethodInfo IsInCombat = AccessTools.PropertyGetter(typeof(CombatState), "IsInCombat");

		private static readonly MethodInfo Replacement = AccessTools.Method(typeof(CombatInvites), "BlocksPrompts", (Type[])null, (Type[])null);

		private static IEnumerable<MethodBase> TargetMethods()
		{
			yield return AccessTools.Method(typeof(SocialPrompts), "Enqueue", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(SocialPrompts), "Tick", (Type[])null, (Type[])null);
			yield return AccessTools.Method(typeof(SocialPrompts), "ShowNextIfPossible", (Type[])null, (Type[])null);
		}

		private static IEnumerable<CodeInstruction> Transpiler(IEnumerable<CodeInstruction> instructions)
		{
			foreach (CodeInstruction instruction in instructions)
			{
				if (CodeInstructionExtensions.Calls(instruction, IsInCombat))
				{
					instruction.operand = Replacement;
				}
				yield return instruction;
			}
		}

		private static bool BlocksPrompts()
		{
			if (Plugin.InvitesDuringCombat.Value)
			{
				return false;
			}
			return CombatState.IsInCombat;
		}
	}
	[HarmonyPatch(typeof(HealthBar), "Update")]
	[HarmonyPriority(0)]
	internal static class HealthText
	{
		private sealed class Label
		{
			public Text Text;

			public Outline Outline;

			public int Shown = int.MinValue;

			public int ShownMax = int.MinValue;

			public bool ShowMax;
		}

		private static readonly ConditionalWeakTable<HealthBar, Label> Labels = new ConditionalWeakTable<HealthBar, Label>();

		private static readonly List<Label> All = new List<Label>();

		private static void Postfix(HealthBar __instance, long playerId, SocialClient client)
		{
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Expected O, but got Unknown
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_007a: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)__instance?._root == (Object)null)
			{
				return;
			}
			Label value = Labels.GetValue(__instance, Create);
			if ((Object)(object)value.Text == (Object)null)
			{
				return;
			}
			MemberVitals val = default(MemberVitals);
			bool num = Plugin.HealthTextEnabled.Value && __instance._root.activeInHierarchy && client != null && client.TryGetVitals(playerId, ref val) && val.MaxHealth > 0f;
			GameObject gameObject = ((Component)value.Text).gameObject;
			if (!num)
			{
				if (gameObject.activeSelf)
				{
					gameObject.SetActive(false);
				}
				return;
			}
			Follow(((Graphic)value.Text).rectTransform, (RectTransform)__instance._root.transform);
			if (!gameObject.activeSelf)
			{
				gameObject.SetActive(true);
			}
			int num2 = ((!val.IsDead) ? Mathf.CeilToInt(val.Health) : 0);
			int num3 = Mathf.CeilToInt(val.MaxHealth);
			if (num2 != value.Shown || num3 != value.ShownMax || value.ShowMax != Plugin.HealthTextShowMax.Value)
			{
				value.Shown = num2;
				value.ShownMax = num3;
				value.ShowMax = Plugin.HealthTextShowMax.Value;
				value.Text.text = (value.ShowMax ? (num2 + " / " + num3) : num2.ToString());
			}
		}

		private static Label Create(HealthBar bar)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0040: Expected O, but got Unknown
			Label label = new Label();
			Transform parent = bar._root.transform.parent;
			if ((Object)(object)parent == (Object)null)
			{
				return label;
			}
			GameObject val = new GameObject("CjayrideHealthText", new Type[1] { typeof(RectTransform) });
			val.transform.SetParent(parent, false);
			val.transform.SetAsLastSibling();
			label.Text = val.AddComponent<Text>();
			label.Text.font = SocialUiFactory.Font;
			label.Text.alignment = (TextAnchor)4;
			label.Text.horizontalOverflow = (HorizontalWrapMode)1;
			label.Text.verticalOverflow = (VerticalWrapMode)1;
			((Graphic)label.Text).raycastTarget = false;
			label.Outline = val.AddComponent<Outline>();
			Style(label);
			All.Add(label);
			return label;
		}

		private static void Follow(RectTransform text, RectTransform bar)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0038: Unknown result type (might be due to invalid IL or missing references)
			//IL_003d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			text.anchorMin = bar.anchorMin;
			text.anchorMax = bar.anchorMax;
			text.pivot = bar.pivot;
			text.anchoredPosition = bar.anchoredPosition;
			Vector3 localScale = ((Transform)bar).localScale;
			Rect rect = bar.rect;
			text.sizeDelta = new Vector2(((Rect)(ref rect)).width * localScale.x, ((Rect)(ref rect)).height * localScale.y);
		}

		private static void Style(Label label)
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0066: Unknown result type (might be due to invalid IL or missing references)
			label.Text.fontSize = Plugin.HealthTextSize.Value;
			((Graphic)label.Text).color = Plugin.HealthTextColor.Value;
			float value = Plugin.HealthTextShadowThickness.Value;
			((Behaviour)label.Outline).enabled = value > 0f;
			((Shadow)label.Outline).effectColor = Plugin.HealthTextShadowColor.Value;
			((Shadow)label.Outline).effectDistance = new Vector2(value, 0f - value);
		}

		internal static void RestyleAll()
		{
			All.RemoveAll((Label l) => (Object)(object)l.Text == (Object)null);
			foreach (Label item in All)
			{
				Style(item);
			}
		}

		internal static void RefreshVisibility()
		{
			All.RemoveAll((Label l) => (Object)(object)l.Text == (Object)null);
			if (Plugin.HealthTextEnabled.Value)
			{
				return;
			}
			foreach (Label item in All)
			{
				((Component)item.Text).gameObject.SetActive(false);
			}
		}
	}
	[BepInPlugin("cjayride.SocialSystemTweaks", "SocialSystem Tweaks", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGuid = "cjayride.SocialSystemTweaks";

		public const string PluginName = "SocialSystem Tweaks";

		public const string PluginVersion = "1.0.0";

		internal static ConfigEntry<bool> InvitesDuringCombat;

		internal static ConfigEntry<bool> HealthTextEnabled;

		internal static ConfigEntry<bool> HealthTextShowMax;

		internal static ConfigEntry<int> HealthTextSize;

		internal static ConfigEntry<Color> HealthTextColor;

		internal static ConfigEntry<Color> HealthTextShadowColor;

		internal static ConfigEntry<float> HealthTextShadowThickness;

		private void Awake()
		{
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Expected O, but got Unknown
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0113: Expected O, but got Unknown
			//IL_01ea: Unknown result type (might be due to invalid IL or missing references)
			InvitesDuringCombat = ((BaseUnityPlugin)this).Config.Bind<bool>("Invites", "ShowDuringCombat", true, "Show party and friend invite prompts right away, even while in combat. Off keeps SocialSystem's behaviour of holding them until combat ends.");
			HealthTextEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("PartyHealthText", "Enabled", true, "Draw the HP number on party member health bars.");
			HealthTextShowMax = ((BaseUnityPlugin)this).Config.Bind<bool>("PartyHealthText", "ShowMaxHealth", true, "Show current / max (for example 85 / 120) instead of only the current HP.");
			HealthTextSize = ((BaseUnityPlugin)this).Config.Bind<int>("PartyHealthText", "FontSize", 12, new ConfigDescription("HP text size.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(6, 32), Array.Empty<object>()));
			HealthTextColor = ((BaseUnityPlugin)this).Config.Bind<Color>("PartyHealthText", "Color", Color.white, "HP text color.");
			HealthTextShadowColor = ((BaseUnityPlugin)this).Config.Bind<Color>("PartyHealthText", "ShadowColor", Color.black, "Border/shadow color around the HP text.");
			HealthTextShadowThickness = ((BaseUnityPlugin)this).Config.Bind<float>("PartyHealthText", "ShadowThickness", 1.5f, new ConfigDescription("Border/shadow thickness around the HP text. 0 removes it.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 5f), Array.Empty<object>()));
			HealthTextSize.SettingChanged += delegate
			{
				HealthText.RestyleAll();
			};
			HealthTextColor.SettingChanged += delegate
			{
				HealthText.RestyleAll();
			};
			HealthTextShadowColor.SettingChanged += delegate
			{
				HealthText.RestyleAll();
			};
			HealthTextShadowThickness.SettingChanged += delegate
			{
				HealthText.RestyleAll();
			};
			HealthTextEnabled.SettingChanged += delegate
			{
				HealthText.RefreshVisibility();
			};
			new Harmony("cjayride.SocialSystemTweaks").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"SocialSystem Tweaks 1.0.0 loaded.");
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}