Decompiled source of More Items Mod v1.1.3

BepInEx/plugins/MoreItemsMod.dll

Decompiled 4 months ago
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
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 MoreCompany;
using Steamworks;
using Steamworks.Data;
using TMPro;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("MoreItemsMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("MoreItemsMod")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("345ecfa1-82f2-45d5-8de3-6325e440df32")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
public class SkeletonKeyItem : GrabbableObject
{
	public override void ItemActivate(bool used, bool buttonDown = true)
	{
		//IL_0027: 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_0041: Unknown result type (might be due to invalid IL or missing references)
		RaycastHit val = default(RaycastHit);
		if (!((Object)(object)base.playerHeldBy == (Object)null) && ((NetworkBehaviour)this).IsOwner && Physics.Raycast(new Ray(((Component)base.playerHeldBy.gameplayCamera).transform.position, ((Component)base.playerHeldBy.gameplayCamera).transform.forward), ref val, 3f, 2816))
		{
			DoorLock component = ((Component)((RaycastHit)(ref val)).transform).GetComponent<DoorLock>();
			if ((Object)(object)component != (Object)null && component.isLocked && !component.isPickingLock)
			{
				component.UnlockDoorSyncWithServer();
			}
		}
	}
}
public class MobileTeleporter : GrabbableObject
{
	private Coroutine beamUpPlayerCoroutine;

	private int[] playersBeingTeleported;

	private PlayerControllerB lastPlayerHeld;

	private List<PlayerControllerB> playersAlive;

	public AudioSource teleporterAudio;

	public AudioClip teleporterSpinSFX;

	public AudioClip teleporterBeamUpSFX;

	public AudioClip beamUpPlayerBodySFX;

	public AudioClip teleporterTickSFX;

	public AudioClip teleporterConfirmSFX;

	public GameObject playerIcon;

	public GameObject playerName;

	private float cooldownTime;

	public float cooldownAmount;

	private bool isTeleporting = false;

	public GameObject screenObject;

	private Material screenMaterial;

	public Camera camera;

	private PlayerControllerB playerToBeamTo;

	private void Awake()
	{
		//IL_000e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: Expected O, but got Unknown
		RenderTexture val = new RenderTexture(256, 256, 16, (RenderTextureFormat)0);
		val.Create();
		camera.targetTexture = val;
		screenMaterial = ((Renderer)screenObject.GetComponent<MeshRenderer>()).material;
		screenMaterial.SetTexture("_EmissiveColorMap", (Texture)(object)val);
		playersBeingTeleported = new int[4] { -1, -1, -1, -1 };
		playersBeingTeleported = new int[MainClass.newPlayerCount];
		for (int i = 0; i < MainClass.newPlayerCount; i++)
		{
			playersBeingTeleported[i] = -1;
		}
	}

	private void setPlayersAliveList()
	{
		playersAlive = new List<PlayerControllerB>();
		for (int i = 0; i < StartOfRound.Instance.allPlayerScripts.Length; i++)
		{
			if (!StartOfRound.Instance.allPlayerScripts[i].isPlayerDead && StartOfRound.Instance.allPlayerScripts[i].isPlayerControlled)
			{
				playersAlive.Add(StartOfRound.Instance.allPlayerScripts[i]);
			}
		}
	}

	private PlayerControllerB getRandomPlayer()
	{
		if (playersAlive != null)
		{
			int index = Random.Range(0, playersAlive.Count);
			return playersAlive[index];
		}
		return null;
	}

	public void PressTeleportButtonOnLocalClient()
	{
		PressTeleportButtonServerRpc();
	}

	[ServerRpc(RequireOwnership = false)]
	public void PressTeleportButtonServerRpc()
	{
		PressTeleportButtonClientRpc();
	}

	[ClientRpc]
	public void PressTeleportButtonClientRpc()
	{
		if (beamUpPlayerCoroutine != null)
		{
			((MonoBehaviour)this).StopCoroutine(beamUpPlayerCoroutine);
		}
		cooldownTime = cooldownAmount;
		beamUpPlayerCoroutine = ((MonoBehaviour)this).StartCoroutine(beamUpPlayer());
	}

	public static async void FillImageWithSteamProfile(RawImage image, SteamId steamId, bool large = true)
	{
		//IL_0019: Unknown result type (might be due to invalid IL or missing references)
		//IL_001a: Unknown result type (might be due to invalid IL or missing references)
		if (SteamClient.IsValid)
		{
			if (large)
			{
				image.texture = (Texture)(object)GetTextureFromImage(await SteamFriends.GetLargeAvatarAsync(steamId));
			}
			else
			{
				image.texture = (Texture)(object)GetTextureFromImage(await SteamFriends.GetSmallAvatarAsync(steamId));
			}
		}
	}

	public static Texture2D GetTextureFromImage(Image? image)
	{
		//IL_0003: Unknown result type (might be due to invalid IL or missing references)
		//IL_000f: 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_001f: Expected O, but got Unknown
		//IL_00be: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a2: 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_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0049: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: 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_0067: Unknown result type (might be due to invalid IL or missing references)
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: 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)
		Texture2D val = new Texture2D((int)image.Value.Width, (int)image.Value.Height);
		Debug.Log((object)"Slot K");
		for (int i = 0; i < image.Value.Width; i++)
		{
			for (int j = 0; j < image.Value.Height; j++)
			{
				Image value = image.Value;
				Color pixel = ((Image)(ref value)).GetPixel(i, j);
				val.SetPixel(i, (int)image.Value.Height - j, new Color((float)(int)pixel.r / 255f, (float)(int)pixel.g / 255f, (float)(int)pixel.b / 255f, (float)(int)pixel.a / 255f));
			}
		}
		Debug.Log((object)"Slot L");
		val.Apply();
		return val;
	}

	private IEnumerator beamUpPlayer()
	{
		setPlayersAliveList();
		for (int i = 0; i <= Random.Range(20, 30); i++)
		{
			teleporterAudio.PlayOneShot(teleporterTickSFX);
			playerToBeamTo = getRandomPlayer();
			if ((Object)(object)playerToBeamTo == (Object)null)
			{
				Debug.Log((object)"Targeted player is null");
				yield break;
			}
			((TMP_Text)playerIcon.GetComponentInChildren<TextMeshProUGUI>()).text = playerToBeamTo.playerUsername;
			if (!GameNetworkManager.Instance.disableSteam)
			{
				FillImageWithSteamProfile(playerIcon.GetComponent<RawImage>(), SteamId.op_Implicit(playerToBeamTo.playerSteamId));
			}
			yield return (object)new WaitForSeconds(0.13f);
		}
		teleporterAudio.PlayOneShot(teleporterConfirmSFX);
		yield return (object)new WaitForSeconds(0.6f);
		teleporterAudio.PlayOneShot(teleporterSpinSFX);
		if ((Object)(object)lastPlayerHeld.redirectToEnemy != (Object)null)
		{
			Debug.Log((object)$"Attemping to teleport enemy '{((Object)((Component)lastPlayerHeld.redirectToEnemy).gameObject).name}' (tied to player #{lastPlayerHeld.playerClientId}) to ship.");
			if (StartOfRound.Instance.shipIsLeaving)
			{
				Debug.Log((object)$"Ship could not teleport enemy '{((Object)((Component)lastPlayerHeld.redirectToEnemy).gameObject).name}' (tied to player #{lastPlayerHeld.playerClientId}) because the ship is leaving the nav mesh.");
			}
			lastPlayerHeld.redirectToEnemy.ShipTeleportEnemy();
			yield return (object)new WaitForSeconds(3f);
			teleporterAudio.PlayOneShot(teleporterBeamUpSFX);
			if (GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			}
		}
		SetPlayerTeleporterId(playerToBeamTo, 1);
		if ((Object)(object)lastPlayerHeld.deadBody != (Object)null)
		{
			if ((Object)(object)lastPlayerHeld.deadBody.beamUpParticle == (Object)null)
			{
				yield break;
			}
			lastPlayerHeld.deadBody.beamUpParticle.Play();
			lastPlayerHeld.deadBody.bodyAudio.PlayOneShot(beamUpPlayerBodySFX);
		}
		else
		{
			lastPlayerHeld.beamUpParticle.Play();
			lastPlayerHeld.movementAudio.PlayOneShot(beamUpPlayerBodySFX);
		}
		Debug.Log((object)"Teleport A");
		yield return (object)new WaitForSeconds(3f);
		bool flag = false;
		if ((Object)(object)lastPlayerHeld.deadBody != (Object)null)
		{
			if ((Object)(object)lastPlayerHeld.deadBody.grabBodyObject == (Object)null || !lastPlayerHeld.deadBody.grabBodyObject.isHeldByEnemy)
			{
				flag = true;
				lastPlayerHeld.deadBody.attachedTo = null;
				lastPlayerHeld.deadBody.attachedLimb = null;
				lastPlayerHeld.deadBody.secondaryAttachedLimb = null;
				lastPlayerHeld.deadBody.secondaryAttachedTo = null;
				if (!playerToBeamTo.isPlayerDead)
				{
					lastPlayerHeld.deadBody.SetRagdollPositionSafely(((Component)playerToBeamTo).transform.position, true);
				}
				else
				{
					lastPlayerHeld.deadBody.SetRagdollPositionSafely(((Component)playerToBeamTo.deadBody).transform.position, true);
				}
				((Component)lastPlayerHeld.deadBody).transform.SetParent(StartOfRound.Instance.elevatorTransform, true);
				if ((Object)(object)lastPlayerHeld.deadBody.grabBodyObject != (Object)null && lastPlayerHeld.deadBody.grabBodyObject.isHeld && (Object)(object)lastPlayerHeld.deadBody.grabBodyObject.playerHeldBy != (Object)null)
				{
					lastPlayerHeld.deadBody.grabBodyObject.playerHeldBy.DropAllHeldItems(true, false);
				}
			}
		}
		else
		{
			flag = true;
			if (Object.op_Implicit((Object)(object)Object.FindObjectOfType<AudioReverbPresets>()))
			{
				Object.FindObjectOfType<AudioReverbPresets>().audioPresets[3].ChangeAudioReverbForPlayer(lastPlayerHeld);
			}
			lastPlayerHeld.isInElevator = true;
			lastPlayerHeld.isInHangarShipRoom = true;
			lastPlayerHeld.isInsideFactory = false;
			lastPlayerHeld.averageVelocity = 0f;
			lastPlayerHeld.velocityLastFrame = Vector3.zero;
			if (!playerToBeamTo.isPlayerDead)
			{
				lastPlayerHeld.TeleportPlayer(((Component)playerToBeamTo).transform.position, false, 0f, false, true);
			}
			else
			{
				lastPlayerHeld.TeleportPlayer(((Component)playerToBeamTo.deadBody).transform.position, false, 0f, false, true);
			}
		}
		Debug.Log((object)"Teleport B");
		SetPlayerTeleporterId(playerToBeamTo, -1);
		if (flag)
		{
			teleporterAudio.PlayOneShot(teleporterBeamUpSFX);
			if (GameNetworkManager.Instance.localPlayerController.isInHangarShipRoom)
			{
				HUDManager.Instance.ShakeCamera((ScreenShakeType)1);
			}
		}
		Debug.Log((object)"Teleport C");
		isTeleporting = false;
	}

	public override void ItemActivate(bool used, bool buttonDown = true)
	{
		((GrabbableObject)this).ItemActivate(used, buttonDown);
		lastPlayerHeld = base.playerHeldBy;
		if (!isTeleporting)
		{
			isTeleporting = true;
			PressTeleportButtonOnLocalClient();
		}
	}

	private void SetPlayerTeleporterId(PlayerControllerB playerScript, int teleporterId)
	{
		playerScript.shipTeleporterId = teleporterId;
		playersBeingTeleported[playerScript.playerClientId] = (int)playerScript.playerClientId;
	}
}
namespace MoreItemsMod;

[BepInPlugin("MadBear422.MoreItemsMod", "More Items Mod", "1.0.0")]
public class MoreItemsModBase : BaseUnityPlugin
{
	private const string modGUID = "MadBear422.MoreItemsMod";

	private const string modName = "More Items Mod";

	private const string modVersion = "1.0.0";

	private readonly Harmony harmony = new Harmony("MadBear422.MoreItemsMod");

	private static MoreItemsModBase Instance;

	internal ManualLogSource mls;

	private void Awake()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			Instance = null;
		}
		mls = Logger.CreateLogSource("MadBear422.MoreItemsMod");
		mls.LogInfo((object)"More Items Mod is Online <3");
		harmony.PatchAll(typeof(MoreItemsModBase));
	}
}