using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using UnityEngine;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("com.github.Quaree.Chained")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.3.0.0")]
[assembly: AssemblyInformationalVersion("0.3.0")]
[assembly: AssemblyProduct("com.github.Quaree.Chained")]
[assembly: AssemblyTitle("Chained")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.3.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
}
}
[CompilerGenerated]
[Microsoft.CodeAnalysis.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 BepInEx
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class BepInAutoPluginAttribute : Attribute
{
public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace BepInEx.Preloader.Core.Patching
{
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
[Conditional("CodeGeneration")]
internal sealed class PatcherAutoPluginAttribute : Attribute
{
public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null)
{
}
}
}
namespace Quaree
{
[BepInPlugin("com.github.Quaree.Chained", "Chained", "0.3.0")]
public class Plugin : BaseUnityPlugin
{
internal static ManualLogSource Log;
private void Awake()
{
//IL_0010: Unknown result type (might be due to invalid IL or missing references)
Log = ((BaseUnityPlugin)this).Logger;
new Harmony("com.github.Quaree.Chained").PatchAll(typeof(ChainedPatch));
}
}
[HarmonyPatch(typeof(Character), "Awake")]
public static class ChainedPatch
{
[HarmonyPostfix]
public static void AwakePatch(Character __instance)
{
if ((Object)(object)((Component)__instance).GetComponent<ChainedController>() == (Object)null)
{
((Component)__instance).gameObject.AddComponent<ChainedController>();
}
}
}
public class ChainedController : MonoBehaviourPunCallbacks
{
private Character character;
private Transform myHip;
private Rigidbody myRb;
private LineRenderer cachedLr;
private static bool isChainedActive = false;
private const float ChainLength = 5f;
private const float PullStrength = 25f;
private float nextScanTime;
private static List<Character> sortedPlayersCache = new List<Character>();
private void Start()
{
character = ((Component)this).GetComponent<Character>();
myHip = GetHip(((Component)this).transform);
if ((Object)(object)myHip != (Object)null)
{
myRb = ((Component)myHip).GetComponent<Rigidbody>();
}
}
private void Update()
{
if (PhotonNetwork.IsMasterClient && character.IsLocal && Input.GetKeyDown((KeyCode)291))
{
((MonoBehaviourPun)this).photonView.RPC("RpcToggleChain", (RpcTarget)0, new object[1] { !isChainedActive });
}
if (isChainedActive && IsActive())
{
if (Time.time > nextScanTime)
{
UpdateSortedPlayers();
nextScanTime = Time.time + 0.5f;
}
DrawChainVisuals();
}
else if ((Object)(object)cachedLr != (Object)null && ((Renderer)cachedLr).enabled)
{
((Renderer)cachedLr).enabled = false;
}
}
private void FixedUpdate()
{
if (isChainedActive && IsActive() && character.IsLocal)
{
ApplyChainPhysics();
}
}
[PunRPC]
public void RpcToggleChain(bool state)
{
isChainedActive = state;
if (!isChainedActive)
{
DestroyAllChainLines();
}
}
private bool IsActive()
{
if (!Object.op_Implicit((Object)(object)character.Ghost))
{
return ((Behaviour)character).isActiveAndEnabled;
}
return false;
}
private void UpdateSortedPlayers()
{
sortedPlayersCache = (from c in Object.FindObjectsByType<Character>((FindObjectsSortMode)0)
where (Object)(object)c != (Object)null && !Object.op_Implicit((Object)(object)c.Ghost) && !c.isBot && ((Behaviour)c).isActiveAndEnabled
orderby ((MonoBehaviourPun)c).photonView.ViewID
select c).ToList();
}
private void ApplyChainPhysics()
{
if ((Object)(object)myHip == (Object)null || (Object)(object)myRb == (Object)null)
{
return;
}
int num = sortedPlayersCache.IndexOf(character);
if (num != -1)
{
if (num > 0)
{
HandlePhysicsConnection(sortedPlayersCache[num - 1]);
}
if (num < sortedPlayersCache.Count - 1)
{
HandlePhysicsConnection(sortedPlayersCache[num + 1]);
}
}
}
private void HandlePhysicsConnection(Character other)
{
//IL_001d: 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_0037: 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_0047: Unknown result type (might be due to invalid IL or missing references)
//IL_004c: Unknown result type (might be due to invalid IL or missing references)
//IL_0050: 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_006a: Unknown result type (might be due to invalid IL or missing references)
//IL_0076: Unknown result type (might be due to invalid IL or missing references)
Transform hip = GetHip(((Component)other).transform);
if (!((Object)(object)hip == (Object)null))
{
float num = Vector3.Distance(myHip.position, hip.position);
if (num > 5f)
{
Vector3 val = hip.position - myHip.position;
Vector3 normalized = ((Vector3)(ref val)).normalized;
float num2 = (num - 5f) * 25f;
myRb.AddForce(normalized * Mathf.Min(num2, 350f), (ForceMode)5);
}
}
}
private void DrawChainVisuals()
{
//IL_0078: Unknown result type (might be due to invalid IL or missing references)
//IL_007e: Unknown result type (might be due to invalid IL or missing references)
int num = sortedPlayersCache.IndexOf(character);
if (num == -1 || num >= sortedPlayersCache.Count - 1 || (Object)(object)myHip == (Object)null)
{
if ((Object)(object)cachedLr != (Object)null)
{
((Renderer)cachedLr).enabled = false;
}
return;
}
Character val = sortedPlayersCache[num + 1];
Transform hip = GetHip(((Component)val).transform);
if ((Object)(object)hip != (Object)null)
{
UpdateChainVisual(myHip.position, hip.position);
}
}
private void UpdateChainVisual(Vector3 start, Vector3 end)
{
//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
//IL_00d4: 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_0036: Expected O, but got Unknown
//IL_005e: Unknown result type (might be due to invalid IL or missing references)
//IL_0068: Expected O, but got Unknown
//IL_008a: 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)
if ((Object)(object)cachedLr == (Object)null)
{
GameObject val = new GameObject($"ChainLine_{((MonoBehaviourPun)character).photonView.ViewID}");
cachedLr = val.AddComponent<LineRenderer>();
cachedLr.positionCount = 2;
((Renderer)cachedLr).material = new Material(Shader.Find("Sprites/Default"));
LineRenderer obj = cachedLr;
LineRenderer obj2 = cachedLr;
Color val2 = default(Color);
((Color)(ref val2))..ctor(0.5f, 0.5f, 0.5f);
obj2.endColor = val2;
obj.startColor = val2;
LineRenderer obj3 = cachedLr;
float startWidth = (cachedLr.endWidth = 0.1f);
obj3.startWidth = startWidth;
}
((Renderer)cachedLr).enabled = true;
cachedLr.SetPosition(0, start);
cachedLr.SetPosition(1, end);
}
private Transform GetHip(Transform root)
{
return ((IEnumerable<Transform>)((Component)root).GetComponentsInChildren<Transform>()).FirstOrDefault((Func<Transform, bool>)((Transform t) => ((Object)t).name == "Hip"));
}
private void DestroyAllChainLines()
{
if ((Object)(object)cachedLr != (Object)null)
{
Object.Destroy((Object)(object)((Component)cachedLr).gameObject);
cachedLr = null;
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}