Decompiled source of RockCompany v1.1.1

RockCompany.dll

Decompiled 9 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using LethalLib.Modules;
using RockCompany.Behaviors;
using Unity.Netcode;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("RockCompany")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("RockCompany")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("bd0221cd-aa3b-4804-b50a-07f379ecb140")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace RockCompany
{
	[BepInPlugin("Jaydesonia.RockCompany", "Rock Company", "1.1.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class RockCompanyBase : BaseUnityPlugin
	{
		private const string modGUID = "Jaydesonia.RockCompany";

		private const string modName = "Rock Company";

		private const string modVersion = "1.1.1";

		private readonly Harmony harmony = new Harmony("Jaydesonia.RockCompany");

		private static RockCompanyBase Instance;

		internal ManualLogSource mls;

		public static AssetBundle MyCustomAssets;

		private Throwable script;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("Jaydesonia.RockCompany");
			mls.LogInfo((object)"The mod has awoke :)");
			harmony.PatchAll(typeof(RockCompanyBase));
			string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
			MyCustomAssets = AssetBundle.LoadFromFile(Path.Combine(directoryName, "mymodassets"));
			if ((Object)(object)MyCustomAssets == (Object)null)
			{
				mls.LogError((object)"Failed to load custom assets.");
				return;
			}
			int num = 40;
			Item val = MyCustomAssets.LoadAsset<Item>("Rock.asset");
			script = val.spawnPrefab.AddComponent<Throwable>();
			((GrabbableObject)script).grabbable = true;
			((GrabbableObject)script).grabbableToEnemies = true;
			((GrabbableObject)script).isInFactory = true;
			((GrabbableObject)script).itemProperties = val;
			val.minValue = 14;
			val.maxValue = 28;
			Utilities.FixMixerGroups(val.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Items.RegisterScrap(val, num, (LevelTypes)(-1));
		}
	}
}
namespace RockCompany.Behaviors
{
	internal class Throwable : PhysicsProp
	{
		public Ray rockThrowRay;

		public RaycastHit rockHit;

		public AnimationCurve rockFallCurve = new AnimationCurve((Keyframe[])(object)new Keyframe[4]
		{
			new Keyframe(0f, 0f),
			new Keyframe(0.2f, 0.5f),
			new Keyframe(0.4f, 0.8f),
			new Keyframe(0.6f, 1f)
		});

		public static AnimationCurve temp = new AnimationCurve((Keyframe[])(object)new Keyframe[3]
		{
			new Keyframe(0f, 0f),
			new Keyframe(0.2f, 0.3f),
			new Keyframe(0.6f, 1f)
		});

		public AnimationCurve rockVerticalFallCurveNoBounce = temp;

		public AnimationCurve rockVerticalFallCurve = temp;

		private RaycastHit[] objectsHitByRock;

		private List<RaycastHit> objectsHitByRockList = new List<RaycastHit>();

		private int shovelMask = 11012424;

		internal ManualLogSource mls;

		private const string modGUID = "Jaydesonia.RockCompany";

		public override void ItemActivate(bool used, bool buttonDown = true)
		{
			//IL_0039: 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_004d: 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_0067: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_0106: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_04dc: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0152: Unknown result type (might be due to invalid IL or missing references)
			//IL_0180: Unknown result type (might be due to invalid IL or missing references)
			//IL_0185: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a6: Unknown result type (might be due to invalid IL or missing references)
			//IL_01c8: Unknown result type (might be due to invalid IL or missing references)
			//IL_01cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01d6: Unknown result type (might be due to invalid IL or missing references)
			//IL_0240: Unknown result type (might be due to invalid IL or missing references)
			//IL_0245: Unknown result type (might be due to invalid IL or missing references)
			//IL_024e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0253: Unknown result type (might be due to invalid IL or missing references)
			//IL_0257: Unknown result type (might be due to invalid IL or missing references)
			//IL_025c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0266: Unknown result type (might be due to invalid IL or missing references)
			//IL_026b: Unknown result type (might be due to invalid IL or missing references)
			//IL_01f2: Unknown result type (might be due to invalid IL or missing references)
			//IL_01fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0203: Unknown result type (might be due to invalid IL or missing references)
			//IL_0207: Unknown result type (might be due to invalid IL or missing references)
			//IL_0316: Unknown result type (might be due to invalid IL or missing references)
			//IL_03ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_03b0: Unknown result type (might be due to invalid IL or missing references)
			//IL_033e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0343: Unknown result type (might be due to invalid IL or missing references)
			//IL_0458: Unknown result type (might be due to invalid IL or missing references)
			//IL_045d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0374: Unknown result type (might be due to invalid IL or missing references)
			//IL_0379: Unknown result type (might be due to invalid IL or missing references)
			//IL_035c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0421: Unknown result type (might be due to invalid IL or missing references)
			mls = Logger.CreateLogSource("Jaydesonia.RockCompany");
			((GrabbableObject)this).ItemActivate(used, buttonDown);
			if (!((NetworkBehaviour)this).IsOwner)
			{
				return;
			}
			objectsHitByRock = Physics.SphereCastAll(new Ray(((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position + Vector3.up * -0.15f, ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.forward), 1f, 20f, shovelMask, (QueryTriggerInteraction)2);
			objectsHitByRockList = objectsHitByRock.OrderBy((RaycastHit x) => ((RaycastHit)(ref x)).distance).ToList();
			PlayerControllerB localPlayerController = GameNetworkManager.Instance.localPlayerController;
			List<int> list = new List<int>();
			IHittable val2 = default(IHittable);
			RaycastHit val3 = default(RaycastHit);
			PlayerControllerB val4 = default(PlayerControllerB);
			EnemyAI val5 = default(EnemyAI);
			for (int i = 0; i < objectsHitByRockList.Count; i++)
			{
				ManualLogSource obj = mls;
				RaycastHit val = objectsHitByRockList[i];
				GameObject gameObject = ((Component)((RaycastHit)(ref val)).collider).gameObject;
				val = objectsHitByRockList[i];
				obj.LogInfo((object)$"OBJECT HIT BY ROCK SPHERECAST: {gameObject}, TYPE: {((object)((Component)((RaycastHit)(ref val)).collider).gameObject).GetType()}");
				val = objectsHitByRockList[i];
				if (((Component)((RaycastHit)(ref val)).transform).gameObject.layer == 8)
				{
					continue;
				}
				val = objectsHitByRockList[i];
				if (((Component)((RaycastHit)(ref val)).transform).gameObject.layer == 11)
				{
					continue;
				}
				val = objectsHitByRockList[i];
				if (!((Component)((RaycastHit)(ref val)).transform).TryGetComponent<IHittable>(ref val2))
				{
					continue;
				}
				val = objectsHitByRockList[i];
				if ((Object)(object)((RaycastHit)(ref val)).transform == (Object)(object)((Component)((GrabbableObject)this).playerHeldBy).transform)
				{
					continue;
				}
				val = objectsHitByRockList[i];
				if (!(((RaycastHit)(ref val)).point == Vector3.zero))
				{
					Vector3 position = ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position;
					val = objectsHitByRockList[i];
					if (Physics.Linecast(position, ((RaycastHit)(ref val)).point, ref val3, StartOfRound.Instance.collidersAndRoomMaskAndDefault))
					{
						continue;
					}
				}
				Vector3 forward = ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.forward;
				val = objectsHitByRockList[i];
				Debug.DrawRay(((RaycastHit)(ref val)).point, Vector3.up * 0.25f, Color.green, 5f);
				try
				{
					mls.LogInfo((object)("ROCK HIT IHITTABLE: " + (object)val2));
					mls.LogInfo((object)("IHITTABLE TYPE: " + ((object)val2).GetType()));
					int num = Random.Range(0, 101);
					if (((object)val2).GetType().Equals(typeof(Landmine)))
					{
						continue;
					}
					if (((object)val2).GetType().Equals(typeof(Turret)))
					{
						val2.Hit(1, forward, ((GrabbableObject)this).playerHeldBy, true);
						continue;
					}
					if (num == 0)
					{
						val = objectsHitByRockList[i];
						if (((Component)((RaycastHit)(ref val)).transform).TryGetComponent<PlayerControllerB>(ref val4))
						{
							val4.KillPlayer(Vector3.zero, true, (CauseOfDeath)1, 0);
							continue;
						}
						val = objectsHitByRockList[i];
						if (((Component)((RaycastHit)(ref val)).transform).TryGetComponent<EnemyAI>(ref val5))
						{
							val5.KillEnemyServerRpc(false);
						}
						continue;
					}
					val = objectsHitByRockList[i];
					if (((Component)((RaycastHit)(ref val)).transform).TryGetComponent<PlayerControllerB>(ref val4))
					{
						mls.LogInfo((object)"Attempting to hit player:");
						if (!list.Contains((int)val4.playerClientId))
						{
							mls.LogInfo((object)"Adding player to list");
							list.Add((int)val4.playerClientId);
							val4.DamagePlayerFromOtherClientServerRpc(1, ((Component)((GrabbableObject)this).playerHeldBy).transform.forward, (int)((GrabbableObject)this).playerHeldBy.playerClientId);
						}
						else
						{
							mls.LogInfo((object)"Player was on list");
						}
					}
					else
					{
						val = objectsHitByRockList[i];
						if (((Component)((RaycastHit)(ref val)).transform).TryGetComponent<EnemyAI>(ref val5))
						{
							val5.HitEnemyServerRpc(1, (int)((GrabbableObject)this).playerHeldBy.playerClientId, true);
						}
					}
				}
				catch (Exception arg)
				{
					Debug.Log((object)$"Exception caught when hitting object with ROCK from player #{((GrabbableObject)this).playerHeldBy.playerClientId}: {arg}");
				}
			}
			((GrabbableObject)this).playerHeldBy.DiscardHeldObject(true, (NetworkObject)null, GetRockThrowDestination(), true);
			list.Clear();
		}

		public Vector3 GetRockThrowDestination()
		{
			//IL_0007: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: 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_0032: 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_0058: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: 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_0077: 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_00dc: 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_00e1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: 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_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
			//IL_0104: Unknown result type (might be due to invalid IL or missing references)
			//IL_010a: Unknown result type (might be due to invalid IL or missing references)
			//IL_015b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0134: Unknown result type (might be due to invalid IL or missing references)
			//IL_0139: Unknown result type (might be due to invalid IL or missing references)
			//IL_0143: Unknown result type (might be due to invalid IL or missing references)
			//IL_0148: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0163: Unknown result type (might be due to invalid IL or missing references)
			Vector3 position = ((Component)this).transform.position;
			Debug.DrawRay(((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position, ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.forward, Color.yellow, 15f);
			rockThrowRay = new Ray(((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.position, ((Component)((GrabbableObject)this).playerHeldBy.gameplayCamera).transform.forward);
			Debug.Log((object)StartOfRound.Instance.collidersAndRoomMaskAndDefault);
			position = ((!Physics.Raycast(rockThrowRay, ref rockHit, 20f, StartOfRound.Instance.collidersAndRoomMaskAndDefault)) ? ((Ray)(ref rockThrowRay)).GetPoint(16f) : ((Ray)(ref rockThrowRay)).GetPoint(((RaycastHit)(ref rockHit)).distance - 0.05f));
			Debug.DrawRay(position, Vector3.down, Color.blue, 15f);
			rockThrowRay = new Ray(position, Vector3.down);
			if (Physics.Raycast(rockThrowRay, ref rockHit, 30f, StartOfRound.Instance.collidersAndRoomMaskAndDefault))
			{
				return ((RaycastHit)(ref rockHit)).point + Vector3.up * 0.05f;
			}
			return ((Ray)(ref rockThrowRay)).GetPoint(30f);
		}

		public override void EquipItem()
		{
			SetControlTipForRock();
			((GrabbableObject)this).EnableItemMeshes(true);
			((GrabbableObject)this).isPocketed = false;
		}

		private void SetControlTipForRock()
		{
			string[] array = new string[1] { "Throw Rock: [LMB]" };
			if (((NetworkBehaviour)this).IsOwner)
			{
				HUDManager.Instance.ChangeControlTipMultiple(array, true, ((GrabbableObject)this).itemProperties);
			}
		}

		public override void FallWithCurve()
		{
			//IL_0002: 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_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_0027: 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_005c: 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_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: 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_014c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0167: Unknown result type (might be due to invalid IL or missing references)
			//IL_0171: Unknown result type (might be due to invalid IL or missing references)
			//IL_017c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0197: Unknown result type (might be due to invalid IL or missing references)
			//IL_01a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_01b7: 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_00de: 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_00f3: 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_0118: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			Vector3 val = ((GrabbableObject)this).startFallingPosition - ((GrabbableObject)this).targetFloorPosition;
			float magnitude = ((Vector3)(ref val)).magnitude;
			((Component)this).transform.rotation = Quaternion.Lerp(((Component)this).transform.rotation, Quaternion.Euler(((GrabbableObject)this).itemProperties.restingRotation.x, ((Component)this).transform.eulerAngles.y, ((GrabbableObject)this).itemProperties.restingRotation.z), 14f * Time.deltaTime / magnitude);
			((Component)this).transform.localPosition = Vector3.Lerp(((GrabbableObject)this).startFallingPosition, ((GrabbableObject)this).targetFloorPosition, rockFallCurve.Evaluate(((GrabbableObject)this).fallTime));
			if (magnitude > 5f)
			{
				((Component)this).transform.localPosition = Vector3.Lerp(new Vector3(((Component)this).transform.localPosition.x, ((GrabbableObject)this).startFallingPosition.y, ((Component)this).transform.localPosition.z), new Vector3(((Component)this).transform.localPosition.x, ((GrabbableObject)this).targetFloorPosition.y, ((Component)this).transform.localPosition.z), rockVerticalFallCurveNoBounce.Evaluate(((GrabbableObject)this).fallTime));
			}
			else
			{
				((Component)this).transform.localPosition = Vector3.Lerp(new Vector3(((Component)this).transform.localPosition.x, ((GrabbableObject)this).startFallingPosition.y, ((Component)this).transform.localPosition.z), new Vector3(((Component)this).transform.localPosition.x, ((GrabbableObject)this).targetFloorPosition.y, ((Component)this).transform.localPosition.z), rockVerticalFallCurve.Evaluate(((GrabbableObject)this).fallTime));
			}
			((GrabbableObject)this).fallTime = ((GrabbableObject)this).fallTime + Mathf.Abs(Time.deltaTime * 12f / magnitude);
		}
	}
}