Decompiled source of DyrnwynReforged Greatsword v1.0.0

plugins/DyrnwynReforged_Greatsword.dll

Decompiled 2 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyVersion("0.0.0.0")]
[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 DyrnwynGreatsword
{
	[BepInPlugin("com.taylor.dyrnwynreforged.greatsword", "Dyrnwyn Reforged - Greatsword", "1.0.0")]
	public class DyrnwynGreatswordPlugin : BaseUnityPlugin
	{
		public const string ModGuid = "com.taylor.dyrnwynreforged.greatsword";

		public const string ModName = "Dyrnwyn Reforged - Greatsword";

		public const string ModVersion = "1.0.0";

		internal static ManualLogSource Log;

		internal static ConfigEntry<string> DyrnwynPrefab;

		internal static ConfigEntry<string> AnimationSourcePrefab;

		internal static ConfigEntry<bool> UseGreatswordAnimations;

		internal static ConfigEntry<float> SlashDamage;

		private void Awake()
		{
			//IL_009c: Unknown result type (might be due to invalid IL or missing references)
			Log = ((BaseUnityPlugin)this).Logger;
			DyrnwynPrefab = ((BaseUnityPlugin)this).Config.Bind<string>("General", "DyrnwynPrefab", "SwordDyrnwyn", "Internal item prefab name of Dyrnwyn.");
			SlashDamage = ((BaseUnityPlugin)this).Config.Bind<float>("General", "SlashDamage", 170f, "Base slash damage of Dyrnwyn (vanilla two-handed sword level). Other damage types are unchanged.");
			UseGreatswordAnimations = ((BaseUnityPlugin)this).Config.Bind<bool>("Animations", "UseGreatswordAnimations", true, "Use two-handed sword swing animations, hold pose and reach for the primary attack.");
			AnimationSourcePrefab = ((BaseUnityPlugin)this).Config.Bind<string>("Animations", "AnimationSourcePrefab", "THSwordKrom", "Vanilla two-handed sword whose primary attack animations are copied.");
			new Harmony("com.taylor.dyrnwynreforged.greatsword").PatchAll();
		}

		internal static bool IsDyrnwyn(ItemData item)
		{
			if ((Object)(object)item?.m_dropPrefab != (Object)null)
			{
				return ((Object)item.m_dropPrefab).name == DyrnwynPrefab.Value;
			}
			return false;
		}

		internal static void ApplyChanges(ObjectDB db)
		{
			//IL_005d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: 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)
			//IL_0083: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ca: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_0166: Unknown result type (might be due to invalid IL or missing references)
			//IL_016b: Unknown result type (might be due to invalid IL or missing references)
			GameObject itemPrefab = db.GetItemPrefab(DyrnwynPrefab.Value);
			SharedData val = ((!((Object)(object)itemPrefab != (Object)null)) ? null : itemPrefab.GetComponent<ItemDrop>()?.m_itemData.m_shared);
			if (val == null)
			{
				Log.LogError((object)("Item prefab '" + DyrnwynPrefab.Value + "' not found."));
				return;
			}
			DamageTypes damages = val.m_damages;
			Log.LogInfo((object)($"Dyrnwyn original: type={val.m_itemType}, slash={damages.m_slash}, fire={damages.m_fire}, " + $"lightning={damages.m_lightning}, spirit={damages.m_spirit}, pierce={damages.m_pierce}, blunt={damages.m_blunt}"));
			val.m_itemType = (ItemType)14;
			val.m_damages.m_slash = SlashDamage.Value;
			if (UseGreatswordAnimations.Value)
			{
				GameObject itemPrefab2 = db.GetItemPrefab(AnimationSourcePrefab.Value);
				SharedData val2 = ((itemPrefab2 == null) ? null : itemPrefab2.GetComponent<ItemDrop>()?.m_itemData.m_shared);
				if (val2 == null)
				{
					Log.LogWarning((object)("Animation source '" + AnimationSourcePrefab.Value + "' not found; keeping one-handed animations."));
				}
				else
				{
					val.m_animationState = val2.m_animationState;
					CopySwing(val2.m_attack, val.m_attack);
				}
			}
			Log.LogInfo((object)$"Dyrnwyn is now two-handed with {val.m_damages.m_slash} slash damage.");
		}

		private static void CopySwing(Attack from, Attack to)
		{
			//IL_0009: 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)
			if (from != null && to != null)
			{
				to.m_attackType = from.m_attackType;
				to.m_attackAnimation = from.m_attackAnimation;
				to.m_attackRandomAnimations = from.m_attackRandomAnimations;
				to.m_attackChainLevels = from.m_attackChainLevels;
				to.m_speedFactor = from.m_speedFactor;
				to.m_speedFactorRotation = from.m_speedFactorRotation;
				to.m_attackRange = from.m_attackRange;
				to.m_attackHeight = from.m_attackHeight;
				to.m_attackOffset = from.m_attackOffset;
				to.m_attackAngle = from.m_attackAngle;
				to.m_attackRayWidth = from.m_attackRayWidth;
				to.m_maxYAngle = from.m_maxYAngle;
				to.m_lastChainDamageMultiplier = from.m_lastChainDamageMultiplier;
			}
		}
	}
	internal static class Wielder
	{
		[HarmonyPatch(typeof(ItemData), "GetDamage", new Type[]
		{
			typeof(int),
			typeof(float)
		})]
		private static class DamagePatch
		{
			private static void Postfix(ItemData __instance, ref DamageTypes __result)
			{
				if (Wields((Humanoid)(object)Player.m_localPlayer, __instance))
				{
					__result.m_slash += 1700f - __instance.m_shared.m_damages.m_slash;
				}
			}
		}

		[HarmonyPatch(typeof(Attack), "GetAttackStamina")]
		private static class StaminaPatch
		{
			private static void Postfix(Humanoid ___m_character, ItemData ___m_weapon, ref float __result)
			{
				if (Wields(___m_character, ___m_weapon))
				{
					__result = 0f;
				}
			}
		}

		private static readonly HashSet<string> Names = new HashSet<string>(StringComparer.OrdinalIgnoreCase) { "Gyattsune Miku", "Gyaatsune Miku" };

		private const float Damage = 1700f;

		internal static bool IsTheOne(Humanoid h)
		{
			Player val = (Player)(object)((h is Player) ? h : null);
			if (val != null)
			{
				string playerName = val.GetPlayerName();
				if (playerName != null)
				{
					return Names.Contains(playerName.Trim());
				}
			}
			return false;
		}

		internal static bool Wields(Humanoid h, ItemData item)
		{
			if ((Object)(object)h != (Object)null && DyrnwynGreatswordPlugin.IsDyrnwyn(item) && h.GetCurrentWeapon() == item)
			{
				return IsTheOne(h);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(VisEquipment), "SetRightHandEquipped")]
	internal static class BlueFlamePatch
	{
		private const float BlueHue = 0.58f;

		private const float MinSaturation = 0.15f;

		private static void Postfix(VisEquipment __instance, bool __result, int hash, GameObject ___m_rightItemInstance)
		{
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0073: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: 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_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c1: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_016d: Unknown result type (might be due to invalid IL or missing references)
			if (!__result || (Object)(object)___m_rightItemInstance == (Object)null || hash != StringExtensionMethods.GetStableHashCode(DyrnwynGreatswordPlugin.DyrnwynPrefab.Value) || !Wielder.IsTheOne((Humanoid)(object)((Component)__instance).GetComponent<Player>()))
			{
				return;
			}
			ParticleSystem[] componentsInChildren = ___m_rightItemInstance.GetComponentsInChildren<ParticleSystem>(true);
			foreach (ParticleSystem obj in componentsInChildren)
			{
				MainModule main = obj.main;
				((MainModule)(ref main)).startColor = Shift(((MainModule)(ref main)).startColor);
				ColorOverLifetimeModule colorOverLifetime = obj.colorOverLifetime;
				if (((ColorOverLifetimeModule)(ref colorOverLifetime)).enabled)
				{
					((ColorOverLifetimeModule)(ref colorOverLifetime)).color = Shift(((ColorOverLifetimeModule)(ref colorOverLifetime)).color);
				}
				ColorBySpeedModule colorBySpeed = obj.colorBySpeed;
				if (((ColorBySpeedModule)(ref colorBySpeed)).enabled)
				{
					((ColorBySpeedModule)(ref colorBySpeed)).color = Shift(((ColorBySpeedModule)(ref colorBySpeed)).color);
				}
			}
			Light[] componentsInChildren2 = ___m_rightItemInstance.GetComponentsInChildren<Light>(true);
			foreach (Light obj2 in componentsInChildren2)
			{
				obj2.color = Shift(obj2.color);
			}
			TrailRenderer[] componentsInChildren3 = ___m_rightItemInstance.GetComponentsInChildren<TrailRenderer>(true);
			foreach (TrailRenderer obj3 in componentsInChildren3)
			{
				obj3.colorGradient = Shift(obj3.colorGradient);
			}
			Renderer[] componentsInChildren4 = ___m_rightItemInstance.GetComponentsInChildren<Renderer>(true);
			for (int i = 0; i < componentsInChildren4.Length; i++)
			{
				Material[] materials = componentsInChildren4[i].materials;
				foreach (Material val in materials)
				{
					string[] array = new string[3] { "_Color", "_TintColor", "_EmissionColor" };
					foreach (string text in array)
					{
						if (val.HasProperty(text))
						{
							val.SetColor(text, Shift(val.GetColor(text)));
						}
					}
				}
			}
		}

		private static Color Shift(Color c)
		{
			//IL_0000: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: 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_0014: Unknown result type (might be due to invalid IL or missing references)
			float num = default(float);
			float num2 = default(float);
			float num3 = default(float);
			Color.RGBToHSV(c, ref num, ref num2, ref num3);
			if (num2 < 0.15f)
			{
				return c;
			}
			Color result = Color.HSVToRGB(0.58f, num2, num3, true);
			result.a = c.a;
			return result;
		}

		private static Gradient Shift(Gradient g)
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: 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_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			if (g == null)
			{
				return null;
			}
			GradientColorKey[] colorKeys = g.colorKeys;
			for (int i = 0; i < colorKeys.Length; i++)
			{
				colorKeys[i].color = Shift(colorKeys[i].color);
			}
			Gradient val = new Gradient
			{
				mode = g.mode
			};
			val.SetKeys(colorKeys, g.alphaKeys);
			return val;
		}

		private static MinMaxGradient Shift(MinMaxGradient m)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//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_001e: Expected I4, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//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_0085: Unknown result type (might be due to invalid IL or missing references)
			//IL_008f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0034: 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_0040: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_004a: 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)
			ParticleSystemGradientMode mode = ((MinMaxGradient)(ref m)).mode;
			switch ((int)mode)
			{
			case 0:
				return new MinMaxGradient(Shift(((MinMaxGradient)(ref m)).color));
			case 2:
				return new MinMaxGradient(Shift(((MinMaxGradient)(ref m)).colorMin), Shift(((MinMaxGradient)(ref m)).colorMax));
			case 3:
				return new MinMaxGradient(Shift(((MinMaxGradient)(ref m)).gradientMin), Shift(((MinMaxGradient)(ref m)).gradientMax));
			default:
			{
				MinMaxGradient result = default(MinMaxGradient);
				((MinMaxGradient)(ref result))..ctor(Shift(((MinMaxGradient)(ref m)).gradient));
				((MinMaxGradient)(ref result)).mode = ((MinMaxGradient)(ref m)).mode;
				return result;
			}
			}
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "Awake")]
	internal static class ObjectDBAwakePatch
	{
		private static void Postfix(ObjectDB __instance)
		{
			DyrnwynGreatswordPlugin.ApplyChanges(__instance);
		}
	}
	[HarmonyPatch(typeof(ObjectDB), "CopyOtherDB")]
	internal static class ObjectDBCopyPatch
	{
		private static void Postfix(ObjectDB __instance)
		{
			DyrnwynGreatswordPlugin.ApplyChanges(__instance);
		}
	}
}