Decompiled source of MeleeSwingCustomization v1.1.1

MeleeSwingCustomization.dll

Decompiled 3 months ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;
using System.Text.RegularExpressions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using GTFO.API.JSON.Converters;
using GTFO.API.Utilities;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Il2CppSystem.Collections.Generic;
using MSC.CustomMeleeData;
using MSC.Dependencies;
using MSC.JSON;
using MSC.Utils;
using MTFO.API;
using Microsoft.CodeAnalysis;
using Player;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("MeleeSwingCustomization")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+fdbdbcccf49cc7726a215cfe486e231f1a71f7f7")]
[assembly: AssemblyProduct("MeleeSwingCustomization")]
[assembly: AssemblyTitle("MeleeSwingCustomization")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
namespace MSC
{
	internal static class Configuration
	{
		public static bool ImproveBatHitbox;

		public static bool DrawDebugHitbox;

		public static float DebugSphereSize;

		private static readonly ConfigFile configFile;

		static Configuration()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			ImproveBatHitbox = true;
			DrawDebugHitbox = false;
			DebugSphereSize = 0.1f;
			configFile = new ConfigFile(Path.Combine(Paths.ConfigPath, "MeleeSwingCustomization.cfg"), true);
			BindAll(configFile);
		}

		internal static void Init()
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			LiveEdit.CreateListener(Paths.ConfigPath, "MeleeSwingCustomization.cfg", false).FileChanged += new LiveEditEventHandler(OnFileChanged);
		}

		private static void OnFileChanged(LiveEditEventArgs _)
		{
			configFile.Reload();
			string text = "Base Settings";
			ImproveBatHitbox = (bool)configFile[text, "Improve Bat Hitbox"].BoxedValue;
			text = "Test Settings";
			MeleeWeaponFirstPerson.DEBUG_TARGETING_ENABLED = (bool)configFile[text, "Show Vanilla Debug Swing Hitbox"].BoxedValue;
			DrawDebugHitbox = (bool)configFile[text, "Show Debug Hitbox Positions"].BoxedValue;
			DebugSphereSize = (float)configFile[text, "Debug Hitbox Size"].BoxedValue;
			DebugUtil.DrawDebugSpheres();
		}

		private static void BindAll(ConfigFile config)
		{
			string text = "Base Settings";
			ImproveBatHitbox = config.Bind<bool>(text, "Improve Bat Hitbox", ImproveBatHitbox, "Improves the hitbox position of bat melee weapons.").Value;
			text = "Test Settings";
			MeleeWeaponFirstPerson.DEBUG_TARGETING_ENABLED = config.Bind<bool>(text, "Show Vanilla Debug Swing Hitbox", false, "Enables the base game debug melee swing hitbox visuals.").Value;
			DrawDebugHitbox = config.Bind<bool>(text, "Show Debug Hitbox Positions", DrawDebugHitbox, "Shows visuals of the held melee weapon's attack offset.\nAlso shows the capsule endpoint if it exists").Value;
			DebugSphereSize = config.Bind<float>(text, "Debug Hitbox Size", DebugSphereSize, "Size of the rendered Hitbox Positions.").Value;
		}
	}
	[BepInPlugin("Dinorush.MeleeSwingCustomization", "MeleeSwingCustomization", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	internal sealed class EntryPoint : BasePlugin
	{
		public const string MODNAME = "MeleeSwingCustomization";

		public override void Load()
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			((BasePlugin)this).Log.LogMessage((object)"Loading MeleeSwingCustomization");
			Configuration.Init();
			MeleeDataManager.Current.Init();
			new Harmony("MeleeSwingCustomization").PatchAll();
			((BasePlugin)this).Log.LogMessage((object)"Loaded MeleeSwingCustomization");
		}
	}
}
namespace MSC.Utils
{
	internal static class DebugUtil
	{
		private static Coroutine? _drawCoroutine;

		public static void DrawDebugSpheres(MeleeWeaponFirstPerson? melee = null)
		{
			if (_drawCoroutine != null)
			{
				CoroutineManager.StopCoroutine(_drawCoroutine);
				_drawCoroutine = null;
			}
			if (!Configuration.DrawDebugHitbox)
			{
				return;
			}
			if ((Object)(object)melee == (Object)null)
			{
				BackpackItem val = default(BackpackItem);
				if (!PlayerBackpackManager.LocalBackpack.TryGetBackpackItem((InventorySlot)10, ref val))
				{
					return;
				}
				melee = ((Il2CppObjectBase)val.Instance).Cast<MeleeWeaponFirstPerson>();
			}
			MeleeData data = MeleeDataManager.Current.GetData(((GameDataBlockBase<MeleeArchetypeDataBlock>)(object)((ItemEquippable)melee).MeleeArchetypeData).persistentID);
			_drawCoroutine = CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(DrawSpheres(melee, data)), (Action)null);
		}

		private static IEnumerator DrawSpheres(MeleeWeaponFirstPerson melee, MeleeData? data)
		{
			while ((Object)(object)melee != (Object)null)
			{
				yield return null;
				PlayerAgent localPlayerAgent = PlayerManager.GetLocalPlayerAgent();
				object obj;
				if (localPlayerAgent == null)
				{
					obj = null;
				}
				else
				{
					FirstPersonItemHolder fPItemHolder = localPlayerAgent.FPItemHolder;
					obj = ((fPItemHolder != null) ? fPItemHolder.WieldedItem : null);
				}
				if ((Object)obj != (Object)(object)melee)
				{
					continue;
				}
				Vector3 position = melee.ModelData.m_damageRefAttack.position;
				if (data?.AttackOffset.HasCapsule ?? false)
				{
					var (val, val2) = data.AttackOffset.CapsuleOffsets(melee.ModelData.m_damageRefAttack, ((ItemEquippable)melee).MeleeArchetypeData);
					DebugDraw3D.DrawSphere(val, Configuration.DebugSphereSize, (val == position) ? ColorExt.Orange(0.4f) : ColorExt.Yellow(0.4f), "");
					DebugDraw3D.DrawSphere(val2, Configuration.DebugSphereSize, (val2 == position) ? ColorExt.Orange(0.4f) : ColorExt.Yellow(0.4f), "");
					if (val != position && val2 != position)
					{
						DebugDraw3D.DrawSphere(position, Configuration.DebugSphereSize, ColorExt.Red(0.4f), "");
					}
				}
				else
				{
					DebugDraw3D.DrawSphere(position, Configuration.DebugSphereSize, ColorExt.Red(0.4f), "");
				}
			}
			_drawCoroutine = null;
		}
	}
	internal static class DinoLogger
	{
		private static readonly ManualLogSource logger = Logger.CreateLogSource("MeleeSwingCustomization");

		public static void Log(string format, params object[] args)
		{
			Log(string.Format(format, args));
		}

		public static void Log(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)8, (object)str);
			}
		}

		public static void Warning(string format, params object[] args)
		{
			Warning(string.Format(format, args));
		}

		public static void Warning(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)4, (object)str);
			}
		}

		public static void Error(string format, params object[] args)
		{
			Error(string.Format(format, args));
		}

		public static void Error(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)2, (object)str);
			}
		}

		public static void Debug(string format, params object[] args)
		{
			Debug(string.Format(format, args));
		}

		public static void Debug(string str)
		{
			if (logger != null)
			{
				logger.Log((LogLevel)32, (object)str);
			}
		}
	}
	public static class RegexUtil
	{
		private static readonly Regex _vectorRegex = new Regex("-?[0-9.]+");

		public static bool TryParseVectorString(string input, out float[] vectorArray)
		{
			try
			{
				MatchCollection matchCollection = _vectorRegex.Matches(input);
				int count = matchCollection.Count;
				if (count < 1)
				{
					throw new Exception();
				}
				vectorArray = new float[count];
				for (int i = 0; i < count; i++)
				{
					Match match = matchCollection[i];
					vectorArray[i] = float.Parse(match.Value, CultureInfo.InvariantCulture);
				}
				return true;
			}
			catch
			{
				vectorArray = null;
				return false;
			}
		}
	}
}
namespace MSC.Patches
{
	[HarmonyPatch(typeof(MeleeWeaponFirstPerson))]
	internal static class MeleeSetupPatches
	{
		private const string BatPrefab = "Assets/AssetPrefabs/Items/Melee/MeleeWeaponFirstPersonBat.prefab";

		private static readonly MeleeData ImprovedBatData = new MeleeData
		{
			AttackOffset = new OffsetData(0f, 0.55f, 0f)
		};

		private static MWS_AttackLight? _lightLeft;

		private static MWS_AttackLight? _lightRight;

		private static IntPtr _cachedPtr = IntPtr.Zero;

		[HarmonyPatch("SetupMeleeAnimations")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_MeleeSetup(MeleeWeaponFirstPerson __instance)
		{
			//IL_0054: Unknown result type (might be due to invalid IL or missing references)
			if (!MeleeDataManager.Current.RegisterMelee(__instance) && Configuration.ImproveBatHitbox)
			{
				List<string> firstPersonPrefabs = ((Item)__instance).ItemDataBlock.FirstPersonPrefabs;
				if (firstPersonPrefabs != null && firstPersonPrefabs.Count > 0 && firstPersonPrefabs[0] == "Assets/AssetPrefabs/Items/Melee/MeleeWeaponFirstPersonBat.prefab")
				{
					__instance.ModelData.m_damageRefAttack.localPosition = ImprovedBatData.AttackOffset.Offset;
				}
			}
			DebugUtil.DrawDebugSpheres(__instance);
		}

		[HarmonyPatch("ChangeState")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_MeleeChangeState(MeleeWeaponFirstPerson __instance, eMeleeWeaponState newState)
		{
			//IL_0063: 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_0097: Expected I4, but got Unknown
			MeleeData data = MeleeDataManager.Current.GetData(((GameDataBlockBase<MeleeArchetypeDataBlock>)(object)((ItemEquippable)__instance).MeleeArchetypeData).persistentID);
			if (data != null)
			{
				if (_cachedPtr != ((Il2CppObjectBase)__instance).Pointer)
				{
					_cachedPtr = ((Il2CppObjectBase)__instance).Pointer;
					_lightLeft = ((Il2CppObjectBase)((Il2CppArrayBase<MWS_Base>)(object)__instance.m_states)[3]).TryCast<MWS_AttackLight>();
					_lightRight = ((Il2CppObjectBase)((Il2CppArrayBase<MWS_Base>)(object)__instance.m_states)[4]).TryCast<MWS_AttackLight>();
				}
				switch (newState - 3)
				{
				case 0:
					_lightLeft.m_wantedNormalSpeed = data.LightAttackSpeed;
					_lightLeft.m_wantedChargeSpeed = data.LightAttackSpeed * 0.3f;
					break;
				case 1:
					_lightRight.m_wantedNormalSpeed = data.LightAttackSpeed;
					_lightRight.m_wantedChargeSpeed = data.LightAttackSpeed * 0.3f;
					break;
				case 2:
				case 3:
					__instance.WeaponAnimator.speed = data.LightAttackSpeed;
					break;
				case 5:
				case 7:
					__instance.WeaponAnimator.speed = data.ChargedAttackSpeed;
					break;
				case 10:
				{
					Animator weaponAnimator = __instance.WeaponAnimator;
					weaponAnimator.speed *= data.PushSpeed;
					break;
				}
				case 4:
				case 6:
				case 8:
				case 9:
					break;
				}
			}
		}
	}
	[HarmonyPatch(typeof(MWS_AttackSwingBase))]
	internal static class MeleeSwingPatches
	{
		private static Coroutine? _capsuleRoutine;

		private static RaycastHit s_rayHit;

		[HarmonyPatch("Enter")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_MeleeEnter(MWS_AttackSwingBase __instance)
		{
			MeleeWeaponFirstPerson weapon = ((MWS_Base)__instance).m_weapon;
			MeleeData data = MeleeDataManager.Current.GetData(((GameDataBlockBase<MeleeArchetypeDataBlock>)(object)((ItemEquippable)weapon).MeleeArchetypeData).persistentID);
			if (data != null && data.AttackOffset.HasCapsule)
			{
				_capsuleRoutine = CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(CapsuleHitDetection(weapon, __instance, data)), (Action)null);
			}
		}

		[HarmonyPatch("Exit")]
		[HarmonyWrapSafe]
		[HarmonyPostfix]
		private static void Post_MeleeExit(MWS_AttackSwingBase __instance)
		{
			if (_capsuleRoutine != null)
			{
				CoroutineManager.StopCoroutine(_capsuleRoutine);
				_capsuleRoutine = null;
			}
		}

		private static IEnumerator CapsuleHitDetection(MeleeWeaponFirstPerson melee, MWS_AttackSwingBase mws, MeleeData data)
		{
			MeleeAttackData attackData = ((MWS_Base)mws).AttackData;
			float endTime = Clock.Time + attackData.m_damageEndTime;
			yield return (object)new WaitForSeconds(attackData.m_damageStartTime);
			MeleeArchetypeDataBlock archBlock = ((ItemEquippable)melee).MeleeArchetypeData;
			FPSCamera camera = ((Item)melee).Owner.FPSCamera;
			while (Clock.Time < endTime && mws != null && !mws.m_targetsFound && (Object)(object)camera != (Object)null)
			{
				if (Physics.Raycast(camera.Position, camera.Forward, ref s_rayHit, archBlock.CameraDamageRayLength, LayerManager.MASK_MELEE_ATTACK_TARGETS_WITH_STATIC))
				{
					IDamageable component = ((Component)((RaycastHit)(ref s_rayHit)).collider).GetComponent<IDamageable>();
					if (component == null || component.GetBaseDamagable().TempSearchID == DamageUtil.SearchID)
					{
						yield return null;
						continue;
					}
				}
				if (CapsuleCheckForHits(camera, archBlock, attackData, data, out List<MeleeWeaponDamageData> hits))
				{
					mws.m_targetsFound = true;
					melee.HitsForDamage = hits;
					mws.OnAttackHit();
				}
				else
				{
					yield return null;
				}
			}
			_capsuleRoutine = null;
		}

		private static bool CapsuleCheckForHits(FPSCamera camera, MeleeArchetypeDataBlock archBlock, MeleeAttackData attackData, MeleeData data, [MaybeNullWhen(false)] out List<MeleeWeaponDamageData> hits)
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0080: 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_0087: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: 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)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: 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_00e0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: 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)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0182: Unknown result type (might be due to invalid IL or missing references)
			//IL_018c: Unknown result type (might be due to invalid IL or missing references)
			//IL_018d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0195: Unknown result type (might be due to invalid IL or missing references)
			//IL_019a: Unknown result type (might be due to invalid IL or missing references)
			//IL_019f: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_01ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_01bd: Expected O, but got Unknown
			hits = null;
			Transform transform = ((Component)attackData.m_damageRef).transform;
			Vector3 position = transform.position;
			Vector3 position2 = camera.Position;
			Vector3 forward = camera.Forward;
			Vector3 val = position - position2;
			float num = Vector3.Dot(forward, ((Vector3)(ref val)).normalized);
			if (num <= 0f && !archBlock.CanHitMultipleEnemies)
			{
				return false;
			}
			OffsetData attackOffset = data.AttackOffset;
			float num2 = attackOffset.CapsuleSize(archBlock, (num > 0.5f) ? (num * (data.AttackSphereCenterMod - 1f)) : 0f);
			(Vector3 start, Vector3 end) tuple = attackOffset.CapsuleOffsets(transform, archBlock);
			Vector3 item = tuple.start;
			Vector3 item2 = tuple.end;
			Collider[] array = Il2CppArrayBase<Collider>.op_Implicit((Il2CppArrayBase<Collider>)(object)Physics.OverlapCapsule(item, item2, num2, LayerManager.MASK_MELEE_ATTACK_TARGETS));
			if (array.Length == 0)
			{
				return false;
			}
			DamageUtil.IncrementSearchID();
			uint searchID = DamageUtil.SearchID;
			List<(Collider, float)> list = new List<(Collider, float)>();
			Collider[] array2 = array;
			foreach (Collider val2 in array2)
			{
				val = ((Component)val2).transform.position - position2;
				list.Add((val2, ((Vector3)(ref val)).sqrMagnitude));
			}
			list.Sort(SqrMagnitudeCompare);
			hits = new List<MeleeWeaponDamageData>();
			foreach (var item4 in list)
			{
				Collider item3 = item4.Item1;
				IDamageable component = ((Component)item3).GetComponent<IDamageable>();
				if (component != null && component.GetBaseDamagable().TempSearchID != searchID)
				{
					component.GetBaseDamagable().TempSearchID = searchID;
					MeleeWeaponDamageData val3 = new MeleeWeaponDamageData
					{
						damageGO = ((Component)item3).gameObject,
						hitPos = ((Component)item3).transform.position
					};
					val = position - ((Component)item3).transform.position;
					val3.hitNormal = ((Vector3)(ref val)).normalized;
					val3.sourcePos = position2;
					val3.damageTargetFound = true;
					MeleeWeaponDamageData val4 = val3;
					hits.Add(val4);
				}
			}
			return hits.Count > 0;
		}

		private static int SqrMagnitudeCompare((Collider, float sqrMagnitude) x, (Collider, float sqrMagnitude) y)
		{
			if (x.sqrMagnitude == y.sqrMagnitude)
			{
				return 0;
			}
			if (!(x.sqrMagnitude < y.sqrMagnitude))
			{
				return 1;
			}
			return -1;
		}
	}
}
namespace MSC.JSON
{
	public static class MSCJson
	{
		private static readonly JsonSerializerOptions _setting;

		static MSCJson()
		{
			//IL_004b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Expected O, but got Unknown
			_setting = new JsonSerializerOptions
			{
				ReadCommentHandling = JsonCommentHandling.Skip,
				IncludeFields = true,
				PropertyNameCaseInsensitive = true,
				WriteIndented = true,
				IgnoreReadOnlyProperties = true
			};
			_setting.Converters.Add(new JsonStringEnumConverter());
			_setting.Converters.Add((JsonConverter)new LocalizedTextConverter());
			_setting.Converters.Add(new Vector3Converter());
			_setting.Converters.Add(new OffsetDataConverter());
		}

		public static T? Deserialize<T>(string json)
		{
			return JsonSerializer.Deserialize<T>(json, _setting);
		}

		public static T? Deserialize<T>(ref Utf8JsonReader reader)
		{
			return JsonSerializer.Deserialize<T>(ref reader, _setting);
		}

		public static object? Deserialize(Type type, string json)
		{
			return JsonSerializer.Deserialize(json, type, _setting);
		}

		public static string Serialize<T>(T value)
		{
			return JsonSerializer.Serialize(value, _setting);
		}

		public static void Serialize<T>(T value, Utf8JsonWriter writer)
		{
			JsonSerializer.Serialize(writer, value, _setting);
		}
	}
	public sealed class OffsetDataConverter : JsonConverter<OffsetData>
	{
		public override OffsetData Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			OffsetData offsetData = new OffsetData();
			switch (reader.TokenType)
			{
			case JsonTokenType.Null:
				return offsetData;
			case JsonTokenType.StartObject:
				while (reader.Read())
				{
					if (reader.TokenType == JsonTokenType.EndObject)
					{
						return offsetData;
					}
					if (reader.TokenType != JsonTokenType.PropertyName)
					{
						throw new JsonException("Expected PropertyName token");
					}
					string @string = reader.GetString();
					reader.Read();
					if (reader.TokenType != JsonTokenType.Null)
					{
						offsetData.DeserializeProperty(@string.ToLowerInvariant().Replace(" ", null), ref reader);
					}
				}
				throw new JsonException("Expected EndObject token");
			case JsonTokenType.String:
			{
				string text = reader.GetString().Trim();
				if (offsetData.ParseOffsetTriplet(text))
				{
					return offsetData;
				}
				throw new JsonException("Bad vector formats detected for OffsetData: " + text);
			}
			default:
				throw new JsonException($"OffsetData Json type: {reader.TokenType} is not implemented!");
			}
		}

		public override void Write(Utf8JsonWriter writer, OffsetData value, JsonSerializerOptions options)
		{
			value.Serialize(writer);
		}
	}
	public sealed class Vector3Converter : JsonConverter<Vector3?>
	{
		public override bool HandleNull => false;

		public override Vector3? Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
		{
			//IL_0002: Unknown result type (might be due to invalid IL or missing references)
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			Vector3 value = default(Vector3);
			switch (reader.TokenType)
			{
			case JsonTokenType.StartObject:
				while (reader.Read())
				{
					if (reader.TokenType == JsonTokenType.EndObject)
					{
						return value;
					}
					if (reader.TokenType != JsonTokenType.PropertyName)
					{
						throw new JsonException("Expected PropertyName token");
					}
					string? @string = reader.GetString();
					reader.Read();
					switch (@string.ToLowerInvariant())
					{
					case "x":
						value.x = reader.GetSingle();
						break;
					case "y":
						value.y = reader.GetSingle();
						break;
					case "z":
						value.z = reader.GetSingle();
						break;
					}
				}
				throw new JsonException("Expected EndObject token");
			case JsonTokenType.String:
			{
				string text = reader.GetString().Trim();
				if (TryParseVector3(text, out var vector))
				{
					return vector;
				}
				throw new JsonException("Vector3 format is not right: " + text);
			}
			default:
				throw new JsonException($"Vector3Json type: {reader.TokenType} is not implemented!");
			}
		}

		private static bool TryParseVector3(string input, out Vector3? vector)
		{
			//IL_000b: 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_0023: Unknown result type (might be due to invalid IL or missing references)
			if (!RegexUtil.TryParseVectorString(input, out float[] vectorArray))
			{
				vector = Vector3.zero;
				return false;
			}
			if (vectorArray.Length < 3)
			{
				vector = Vector3.zero;
				return false;
			}
			vector = new Vector3(vectorArray[0], vectorArray[1], vectorArray[2]);
			return true;
		}

		public override void Write(Utf8JsonWriter writer, Vector3? value, JsonSerializerOptions options)
		{
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (!value.HasValue)
			{
				writer.WriteNullValue();
			}
			else
			{
				writer.WriteStringValue($"({value.Value.x} {value.Value.y} {value.Value.z})");
			}
		}
	}
}
namespace MSC.Dependencies
{
	internal static class MTFOWrapper
	{
		public const string GUID = "com.dak.MTFO";

		public static string GameDataPath => MTFOPathAPI.RundownPath;

		public static string CustomPath => MTFOPathAPI.CustomPath;

		public static bool HasCustomDatablocks
		{
			get
			{
				if (HasMTFO)
				{
					return UnsafeHasCustomDatablocks;
				}
				return false;
			}
		}

		private static bool UnsafeHasCustomDatablocks => MTFOPathAPI.HasRundownPath;

		public static bool HasMTFO { get; private set; }

		static MTFOWrapper()
		{
			HasMTFO = ((BaseChainloader<BasePlugin>)(object)IL2CPPChainloader.Instance).Plugins.ContainsKey("com.dak.MTFO");
		}
	}
}
namespace MSC.CustomMeleeData
{
	public sealed class MeleeData
	{
		public uint ArchetypeID { get; set; }

		public string Name { get; set; } = string.Empty;


		public OffsetData AttackOffset { get; set; } = new OffsetData();


		public Vector3? PushOffset { get; set; }

		public float LightAttackSpeed { get; set; } = 1f;


		public float ChargedAttackSpeed { get; set; } = 1f;


		public float PushSpeed { get; set; } = 1f;


		public float AttackSphereCenterMod { get; set; } = 1.9f;

	}
	public sealed class MeleeDataManager
	{
		public static readonly MeleeDataManager Current = new MeleeDataManager();

		private readonly Dictionary<string, List<MeleeData>> _fileData = new Dictionary<string, List<MeleeData>>();

		private readonly Dictionary<uint, MeleeData> _idToData = new Dictionary<uint, MeleeData>();

		private readonly Dictionary<uint, MeleeData> _cachedData = new Dictionary<uint, MeleeData>();

		private readonly List<MeleeWeaponFirstPerson> _listeners = new List<MeleeWeaponFirstPerson>();

		private readonly LiveEditListener? _liveEditListener;

		private void FileChanged(LiveEditEventArgs e)
		{
			LiveEditEventArgs e2 = e;
			DinoLogger.Warning("LiveEdit File Changed: " + e2.FullPath);
			LiveEdit.TryReadFileContent(e2.FullPath, (Action<string>)delegate(string content)
			{
				ReadFileContent(e2.FullPath, content);
				PrintCustomIDs();
			});
		}

		private void FileDeleted(LiveEditEventArgs e)
		{
			DinoLogger.Warning("LiveEdit File Removed: " + e.FullPath);
			RemoveFile(e.FullPath);
			PrintCustomIDs();
		}

		private void FileCreated(LiveEditEventArgs e)
		{
			LiveEditEventArgs e2 = e;
			DinoLogger.Warning("LiveEdit File Created: " + e2.FullPath);
			LiveEdit.TryReadFileContent(e2.FullPath, (Action<string>)delegate(string content)
			{
				ReadFileContent(e2.FullPath, content);
				PrintCustomIDs();
			});
		}

		private void ReadFileContent(string file, string content)
		{
			RemoveFile(file);
			List<MeleeData> list = null;
			try
			{
				list = MSCJson.Deserialize<List<MeleeData>>(content);
			}
			catch (JsonException ex)
			{
				DinoLogger.Error("Error parsing json " + file);
				DinoLogger.Error(ex.Message);
			}
			if (list != null)
			{
				AddFile(file, list);
			}
		}

		private void RemoveFile(string file)
		{
			if (!_fileData.ContainsKey(file))
			{
				return;
			}
			foreach (MeleeData item in _fileData[file])
			{
				_idToData.Remove(item.ArchetypeID);
			}
			_fileData.Remove(file);
			ResetListeners();
		}

		private void AddFile(string file, List<MeleeData> dataList)
		{
			_fileData.Add(file, dataList);
			foreach (MeleeData data in dataList)
			{
				if (data.ArchetypeID != 0)
				{
					if (_idToData.ContainsKey(data.ArchetypeID))
					{
						DinoLogger.Warning($"Duplicate archetype ID {data.ArchetypeID} detected. Previous name: {_idToData[data.ArchetypeID].Name}, new name: {data.Name}");
					}
					_idToData[data.ArchetypeID] = data;
					FillDataWithCache(data.ArchetypeID);
				}
			}
			ResetListeners();
		}

		private void ResetListeners()
		{
			for (int num = _listeners.Count - 1; num >= 0; num--)
			{
				if ((Object)(object)_listeners[num] != (Object)null)
				{
					SetMeleeData(_listeners[num]);
					DebugUtil.DrawDebugSpheres(_listeners[num]);
				}
				else
				{
					_listeners.RemoveAt(num);
				}
			}
		}

		private void PrintCustomIDs()
		{
			if (_idToData.Count > 0)
			{
				StringBuilder stringBuilder = new StringBuilder("Found custom blocks for archetype IDs: ");
				stringBuilder.AppendJoin(", ", _idToData.Keys.ToImmutableSortedSet());
				DinoLogger.Log(stringBuilder.ToString());
			}
		}

		private MeleeDataManager()
		{
			//IL_011d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0127: Expected O, but got Unknown
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_013e: Expected O, but got Unknown
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0155: Expected O, but got Unknown
			if (!MTFOWrapper.HasCustomDatablocks)
			{
				DinoLogger.Log("No MTFO datablocks detected. Restricting to bat changes...");
				return;
			}
			string text = Path.Combine(MTFOWrapper.CustomPath, "MeleeSwingCustomization");
			if (!Directory.Exists(text))
			{
				DinoLogger.Log("No directory detected. Creating " + text + "/Template.json");
				Directory.CreateDirectory(text);
				StreamWriter streamWriter = File.CreateText(Path.Combine(text, "Template.json"));
				streamWriter.WriteLine(MSCJson.Serialize(new List<MeleeData>(MeleeDataTemplate.Template)));
				streamWriter.Flush();
				streamWriter.Close();
			}
			else
			{
				DinoLogger.Log("Directory detected. " + text);
			}
			foreach (string item in Directory.EnumerateFiles(text, "*.json", SearchOption.AllDirectories))
			{
				string content = File.ReadAllText(item);
				ReadFileContent(item, content);
			}
			PrintCustomIDs();
			_liveEditListener = LiveEdit.CreateListener(text, "*.json", true);
			_liveEditListener.FileCreated += new LiveEditEventHandler(FileCreated);
			_liveEditListener.FileChanged += new LiveEditEventHandler(FileChanged);
			_liveEditListener.FileDeleted += new LiveEditEventHandler(FileDeleted);
		}

		internal void Init()
		{
		}

		public bool RegisterMelee(MeleeWeaponFirstPerson melee)
		{
			if (!MTFOWrapper.HasCustomDatablocks)
			{
				return false;
			}
			CacheData(melee);
			AddMeleeListener(melee);
			return SetMeleeData(melee);
		}

		public bool HasData(uint id)
		{
			return _idToData.ContainsKey(id);
		}

		public MeleeData? GetData(uint id)
		{
			return _idToData.GetValueOrDefault(id);
		}

		private void CacheData(MeleeWeaponFirstPerson melee)
		{
			//IL_0033: 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)
			uint persistentID = ((GameDataBlockBase<MeleeArchetypeDataBlock>)(object)((ItemEquippable)melee).MeleeArchetypeData).persistentID;
			if (!_cachedData.ContainsKey(persistentID))
			{
				MeleeData value = new MeleeData
				{
					ArchetypeID = persistentID,
					AttackOffset = new OffsetData(melee.ModelData.m_damageRefAttack.localPosition),
					PushOffset = melee.ModelData.m_damageRefPush.localPosition
				};
				_cachedData.Add(persistentID, value);
				FillDataWithCache(persistentID);
			}
		}

		private void FillDataWithCache(uint id)
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			if (_idToData.TryGetValue(id, out MeleeData value) && _cachedData.TryGetValue(id, out MeleeData value2))
			{
				if (!value.AttackOffset.HasOffset)
				{
					value.AttackOffset.Offset = value2.AttackOffset.Offset;
				}
				if (!value.PushOffset.HasValue)
				{
					value.PushOffset = value2.PushOffset;
				}
			}
		}

		private void AddMeleeListener(MeleeWeaponFirstPerson melee)
		{
			MeleeWeaponFirstPerson melee2 = melee;
			if (!_listeners.Any((MeleeWeaponFirstPerson listener) => ((listener != null) ? new int?(((Object)listener).GetInstanceID()) : null) == ((Object)melee2).GetInstanceID()))
			{
				_listeners.Add(melee2);
			}
		}

		private bool SetMeleeData(MeleeWeaponFirstPerson melee)
		{
			//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00eb: 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_00a7: Unknown result type (might be due to invalid IL or missing references)
			uint persistentID = ((GameDataBlockBase<MeleeArchetypeDataBlock>)(object)((ItemEquippable)melee).MeleeArchetypeData).persistentID;
			if (!_cachedData.TryGetValue(persistentID, out MeleeData value))
			{
				DinoLogger.Error($"Unable to get original data for melee {((Object)melee).name}, archetype ID {persistentID}");
				return false;
			}
			Transform damageRefAttack = melee.ModelData.m_damageRefAttack;
			Transform damageRefPush = melee.ModelData.m_damageRefPush;
			if (_idToData.TryGetValue(persistentID, out MeleeData value2))
			{
				damageRefAttack.localPosition = value2.AttackOffset.Offset;
				damageRefPush.localPosition = value2.PushOffset.Value;
				melee.m_attackDamageSphereDotScale = value2.AttackSphereCenterMod - 1f;
				SetMeleeAttackTimings(melee, value2);
				return true;
			}
			damageRefAttack.localPosition = value.AttackOffset.Offset;
			damageRefPush.localPosition = value.PushOffset.Value;
			melee.m_attackDamageSphereDotScale = value.AttackSphereCenterMod - 1f;
			SetMeleeAttackTimings(melee, value);
			return false;
		}

		private void SetMeleeAttackTimings(MeleeWeaponFirstPerson melee, MeleeData data)
		{
			float mod = 1f / data.LightAttackSpeed;
			Il2CppReferenceArray<MWS_Base> states = melee.m_states;
			MeleeAnimationSetDataBlock meleeAnimationData = ((ItemEquippable)melee).MeleeAnimationData;
			CopyMeleeData(((Il2CppArrayBase<MWS_Base>)(object)states)[3].AttackData, meleeAnimationData.FPAttackMissLeft, mod);
			CopyMeleeData(((Il2CppArrayBase<MWS_Base>)(object)states)[4].AttackData, meleeAnimationData.FPAttackMissRight, mod);
			CopyMeleeData(((Il2CppArrayBase<MWS_Base>)(object)states)[5].AttackData, meleeAnimationData.FPAttackHitLeft, mod);
			CopyMeleeData(((Il2CppArrayBase<MWS_Base>)(object)states)[6].AttackData, meleeAnimationData.FPAttackHitRight, mod);
			mod = 1f / data.ChargedAttackSpeed;
			CopyMeleeData(((Il2CppArrayBase<MWS_Base>)(object)states)[8].AttackData, meleeAnimationData.FPAttackChargeUpReleaseLeft, mod);
			CopyMeleeData(((Il2CppArrayBase<MWS_Base>)(object)states)[10].AttackData, meleeAnimationData.FPAttackChargeUpReleaseRight, mod);
			CopyMeleeData(((Il2CppArrayBase<MWS_Base>)(object)states)[11].AttackData, meleeAnimationData.FPAttackChargeUpHitLeft, mod);
			CopyMeleeData(((Il2CppArrayBase<MWS_Base>)(object)states)[12].AttackData, meleeAnimationData.FPAttackChargeUpHitRight, mod);
			CopyMeleeData(mod: 1f / data.PushSpeed, data: ((Il2CppArrayBase<MWS_Base>)(object)states)[13].AttackData, animData: meleeAnimationData.FPAttackPush);
		}

		private static void CopyMeleeData(MeleeAttackData data, MeleeAttackData animData, float mod = 1f)
		{
			data.m_attackLength = animData.AttackLengthTime * mod;
			data.m_attackHitTime = animData.AttackHitTime * mod;
			data.m_damageStartTime = animData.DamageStartTime * mod;
			data.m_damageEndTime = animData.DamageEndTime * mod;
			data.m_attackCamFwdHitTime = animData.AttackCamFwdHitTime * mod;
			data.m_comboEarlyTime = animData.ComboEarlyTime * mod;
		}
	}
	internal static class MeleeDataTemplate
	{
		public static MeleeData[] Template = new MeleeData[6]
		{
			new MeleeData
			{
				ArchetypeID = 0u,
				Name = "Sledgehammer",
				AttackOffset = new OffsetData(0f, -0.111f, 0.483f),
				PushOffset = new Vector3(0f, -0.005f, 0.041f)
			},
			new MeleeData
			{
				ArchetypeID = 0u,
				Name = "Knife",
				AttackOffset = new OffsetData(0f, 0.248f, 0.076f),
				PushOffset = new Vector3(0f, 0.0228f, 1.061f)
			},
			new MeleeData
			{
				ArchetypeID = 0u,
				Name = "Spear",
				AttackOffset = new OffsetData(0f, 0.972f, -0.002f),
				PushOffset = new Vector3(0f, -0.501f, 0.005f)
			},
			new MeleeData
			{
				ArchetypeID = 0u,
				Name = "Bat",
				AttackOffset = new OffsetData(0f, 0.4047f, 0f),
				PushOffset = new Vector3(0f, -0.0817f, 0f)
			},
			new MeleeData
			{
				ArchetypeID = 0u,
				Name = "Improved Bat",
				AttackOffset = new OffsetData(0f, 0.55f, 0f)
			},
			new MeleeData
			{
				ArchetypeID = 0u,
				Name = "Improved Spear",
				AttackOffset = new OffsetData(((Vector3?)new Vector3(0f, 0.972f, -0.002f), (Vector3?)new Vector3(0f, -0.2f, 0f)))
			}
		};
	}
	public sealed class OffsetData
	{
		private Vector3? _offset;

		public Vector3? _capsuleOffset;

		public Vector3? _capsuleOffsetEnd;

		private bool _capsuleUseCamFwd;

		private float _capsuleCamFwdAdd;

		private float _capsuleSize;

		private bool _capsuleUseCenterMod;

		public Vector3 Offset
		{
			get
			{
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				return _offset.Value;
			}
			set
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				_offset = value;
			}
		}

		public bool HasOffset => _offset.HasValue;

		public bool HasCapsule
		{
			get
			{
				if (!_capsuleUseCamFwd)
				{
					return _capsuleOffset.HasValue;
				}
				return true;
			}
		}

		public OffsetData(Vector3? offset = null)
		{
			_offset = offset;
		}

		public OffsetData(float x, float y, float z)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			_offset = new Vector3(x, y, z);
		}

		public OffsetData((Vector3?, Vector3?) offsets)
		{
			(_offset, _capsuleOffset) = offsets;
		}

		public float CapsuleSize(MeleeArchetypeDataBlock data, float dotScale = 0f)
		{
			float num = ((_capsuleSize > 0f) ? _capsuleSize : data.AttackSphereRadius);
			if (!_capsuleUseCenterMod)
			{
				return num;
			}
			return num * (1f + dotScale);
		}

		public (Vector3 start, Vector3 end) CapsuleOffsets(Transform transform, MeleeArchetypeDataBlock data)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0006: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: 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_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_010f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0116: Unknown result type (might be due to invalid IL or missing references)
			//IL_011b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Unknown result type (might be due to invalid IL or missing references)
			//IL_013b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0142: Unknown result type (might be due to invalid IL or missing references)
			//IL_0147: Unknown result type (might be due to invalid IL or missing references)
			//IL_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0133: 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_0046: Unknown result type (might be due to invalid IL or missing references)
			//IL_0047: 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_0055: 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_00bb: 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_00c3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ef: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0103: Unknown result type (might be due to invalid IL or missing references)
			//IL_0072: 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_007a: 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_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_008b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0092: Unknown result type (might be due to invalid IL or missing references)
			//IL_0097: Unknown result type (might be due to invalid IL or missing references)
			//IL_009c: 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_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
			Vector3 localPosition = transform.localPosition;
			Vector3 position = transform.parent.position;
			Quaternion rotation = transform.parent.rotation;
			if (_capsuleUseCamFwd)
			{
				float num = _capsuleCamFwdAdd + data.CameraDamageRayLength;
				if (!_capsuleOffset.HasValue)
				{
					return (position, position + rotation * ((Vector3)(ref localPosition)).normalized * num);
				}
				Vector3 val;
				if (!_capsuleOffsetEnd.HasValue)
				{
					Vector3 item = position + rotation * _capsuleOffset.Value;
					val = localPosition - _capsuleOffset.Value;
					return (item, position + rotation * ((Vector3)(ref val)).normalized * num);
				}
				Vector3 item2 = position + rotation * _capsuleOffset.Value;
				val = _capsuleOffsetEnd.Value - _capsuleOffset.Value;
				return (item2, position + rotation * ((Vector3)(ref val)).normalized * num);
			}
			return (position + rotation * _capsuleOffset.Value, _capsuleOffsetEnd.HasValue ? (position + rotation * _capsuleOffsetEnd.Value) : transform.position);
		}

		public void Serialize(Utf8JsonWriter writer)
		{
			if (!_offset.HasValue)
			{
				writer.WriteNullValue();
				return;
			}
			if (!_capsuleOffset.HasValue)
			{
				MSCJson.Serialize(_offset, writer);
				return;
			}
			writer.WriteStartObject();
			writer.WritePropertyName("Offset");
			if (_offset.HasValue)
			{
				string text = MSCJson.Serialize(_offset);
				StringBuilder stringBuilder = new StringBuilder(text.Substring(1, text.Length - 1 - 1));
				if (_capsuleOffset.HasValue)
				{
					text = MSCJson.Serialize(_capsuleOffset);
					stringBuilder.Append(" " + text.Substring(1, text.Length - 1 - 1));
				}
				if (_capsuleOffsetEnd.HasValue)
				{
					text = MSCJson.Serialize(_capsuleOffsetEnd);
					stringBuilder.Append(" " + text.Substring(1, text.Length - 1 - 1));
				}
				writer.WriteStringValue(stringBuilder.ToString());
			}
			else
			{
				writer.WriteNullValue();
			}
			writer.WritePropertyName(PrettyName("_capsuleOffset"));
			if (_capsuleOffset.HasValue && !_offset.HasValue)
			{
				string text = MSCJson.Serialize(_capsuleOffset);
				StringBuilder stringBuilder2 = new StringBuilder(text.Substring(1, text.Length - 1 - 1));
				if (_capsuleOffsetEnd.HasValue)
				{
					text = MSCJson.Serialize(_capsuleOffsetEnd);
					stringBuilder2.Append(" " + text.Substring(1, text.Length - 1 - 1));
				}
				writer.WriteStringValue(stringBuilder2.ToString());
			}
			else
			{
				writer.WriteNullValue();
			}
			writer.WriteBoolean(PrettyName("_capsuleUseCamFwd"), _capsuleUseCamFwd);
			writer.WriteNumber(PrettyName("_capsuleCamFwdAdd"), _capsuleCamFwdAdd);
			writer.WriteNumber(PrettyName("_capsuleSize"), _capsuleSize);
			writer.WriteBoolean(PrettyName("_capsuleUseCenterMod"), _capsuleUseCenterMod);
			writer.WriteEndObject();
		}

		private static string PrettyName(string name)
		{
			return char.ToUpper(name[1]) + name.Substring(2, name.Length - 2);
		}

		public void DeserializeProperty(string propertyName, ref Utf8JsonReader reader)
		{
			if (propertyName == null)
			{
				return;
			}
			switch (propertyName.Length)
			{
			case 16:
				switch (propertyName[7])
				{
				case 'u':
					if (propertyName == "capsuleusecamfwd")
					{
						_capsuleUseCamFwd = reader.GetBoolean();
					}
					break;
				case 'c':
					if (propertyName == "capsulecamfwdadd")
					{
						_capsuleCamFwdAdd = reader.GetSingle();
					}
					break;
				}
				break;
			case 7:
				if (!(propertyName == "offsets"))
				{
					break;
				}
				goto IL_00a5;
			case 6:
				if (!(propertyName == "offset"))
				{
					break;
				}
				goto IL_00a5;
			case 13:
				if (propertyName == "capsuleoffset")
				{
					ParseCapsuleOffset(reader.GetString().Trim());
				}
				break;
			case 11:
				if (propertyName == "capsulesize")
				{
					_capsuleSize = reader.GetSingle();
				}
				break;
			case 19:
				{
					if (propertyName == "capsuleusecentermod")
					{
						_capsuleUseCenterMod = reader.GetBoolean();
					}
					break;
				}
				IL_00a5:
				ParseOffsetTriplet(reader.GetString().Trim());
				break;
			}
		}

		public bool ParseOffsetTriplet(string text)
		{
			if (TryParseVector3OffsetTriplet(text, out var vectors))
			{
				(_offset, _capsuleOffset, _capsuleOffsetEnd) = vectors;
				return true;
			}
			return false;
		}

		private bool ParseCapsuleOffset(string text)
		{
			if (TryParseVector3OffsetTriplet(text, out var vectors))
			{
				(_capsuleOffset, _capsuleOffsetEnd, _) = vectors;
				return true;
			}
			return false;
		}

		public static bool TryParseVector3OffsetTriplet(string input, out (Vector3?, Vector3?, Vector3?) vectors)
		{
			//IL_006a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bf: Unknown result type (might be due to invalid IL or missing references)
			if (!RegexUtil.TryParseVectorString(input, out float[] vectorArray))
			{
				vectors = (null, null, null);
				return false;
			}
			if (vectorArray.Length < 3)
			{
				vectors = (null, null, null);
				return false;
			}
			vectors.Item1 = new Vector3(vectorArray[0], vectorArray[1], vectorArray[2]);
			vectors.Item2 = ((vectorArray.Length >= 6) ? new Vector3?(new Vector3(vectorArray[3], vectorArray[4], vectorArray[5])) : null);
			vectors.Item3 = ((vectorArray.Length >= 9) ? new Vector3?(new Vector3(vectorArray[6], vectorArray[7], vectorArray[8])) : null);
			return true;
		}
	}
}