Decompiled source of Random TP v1.1.0

Random_TP.dll

Decompiled 7 hours ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Photon.Pun;
using UnityEngine;
using UnityEngine.Networking;
using config;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("Random_TP")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("HP")]
[assembly: AssemblyProduct("Random_TP")]
[assembly: AssemblyCopyright("Copyright © HP 2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("b61299c4-e630-4ce9-b767-145d52732b87")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("miko.repo.random_tp", "Random TP", "1.0.0")]
public class Random_TP : BaseUnityPlugin
{
	[CompilerGenerated]
	private sealed class <Load>d__7 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		public string path;

		public Action<AudioClip> onLoaded;

		public Random_TP <>4__this;

		private UnityWebRequest <www>5__1;

		private AudioClip <clip>5__2;

		private TP_SoundHandler <soundHandler>5__3;

		private Exception <e>5__4;

		private Exception <e>5__5;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <Load>d__7(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<www>5__1 = null;
			<clip>5__2 = null;
			<soundHandler>5__3 = null;
			<e>5__4 = null;
			<e>5__5 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Invalid comparison between Unknown and I4
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				Debug.Log((object)("Start load audio : " + path));
				Debug.Log((object)(File.Exists(path) ? "Audio file exists" : "Audio file NOT FOUND"));
				<www>5__1 = null;
				try
				{
					<www>5__1 = UnityWebRequestMultimedia.GetAudioClip("file:///" + path.Replace("\\", "/"), (AudioType)14);
				}
				catch (Exception ex)
				{
					<e>5__4 = ex;
					Debug.LogError((object)("[ModAudio INIT ERROR] " + <e>5__4));
					return false;
				}
				<>2__current = <www>5__1.SendWebRequest();
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				if ((int)<www>5__1.result != 1)
				{
					Debug.LogError((object)("[ModAudio REQUEST ERROR] " + <www>5__1.error));
					return false;
				}
				try
				{
					<clip>5__2 = DownloadHandlerAudioClip.GetContent(<www>5__1);
				}
				catch (Exception ex)
				{
					<e>5__5 = ex;
					Debug.LogError((object)("[ModAudio CLIP ERROR] " + <e>5__5));
					return false;
				}
				onLoaded?.Invoke(<clip>5__2);
				<soundHandler>5__3 = ((Component)PlayerController.instance).gameObject.GetComponent<TP_SoundHandler>();
				if ((Object)(object)<soundHandler>5__3 != (Object)null)
				{
					if (path.Contains("Leave"))
					{
						<soundHandler>5__3.tpSoundLeave = <clip>5__2;
					}
					else if (path.Contains("Arrive"))
					{
						<soundHandler>5__3.tpSoundArrive = <clip>5__2;
					}
				}
				Debug.Log((object)("Load with success : " + path));
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private Harmony harmony;

	public static AudioClip tpSoundLeave;

	public static AudioClip tpSoundArrive;

	public string modFolderPath;

	private void Awake()
	{
		//IL_0007: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		harmony = new Harmony("miko.repo.random_tp");
		harmony.PatchAll();
		modFolderPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		PhysGrabber_StartGrabbing_Patch.random_tp = this;
		string path = Path.Combine(modFolderPath, "Enderman_TP_Leave.ogg");
		((MonoBehaviour)this).StartCoroutine(Load(path, delegate(AudioClip clip)
		{
			tpSoundLeave = clip;
		}));
		string path2 = Path.Combine(modFolderPath, "Enderman_TP_Arrive.ogg");
		((MonoBehaviour)this).StartCoroutine(Load(path2, delegate(AudioClip clip)
		{
			tpSoundArrive = clip;
		}));
		ConfigManager.Initialize(((BaseUnityPlugin)this).Config);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Random TP has loaded !");
	}

	public void PlayTPSoundLeaveNetworked()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		if (PhotonNetwork.InRoom)
		{
			PhotonView val = PhotonView.Get(((Component)PlayerController.instance).gameObject);
			val.RPC("RPC_PlayTPSoundLeave", (RpcTarget)0, new object[1] { ((Component)PlayerController.instance).transform.position });
			Debug.Log((object)"Send message");
		}
		else
		{
			TP_SoundHandler component = ((Component)PlayerController.instance).gameObject.GetComponent<TP_SoundHandler>();
			component.RPC_PlayTPSoundLeave(((Component)PlayerController.instance).transform.position);
		}
	}

	public void PlayTPSoundArriveNetworked()
	{
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0034: Unknown result type (might be due to invalid IL or missing references)
		if (PhotonNetwork.InRoom)
		{
			PhotonView val = PhotonView.Get(((Component)PlayerController.instance).gameObject);
			val.RPC("RPC_PlayTPSoundArrive", (RpcTarget)0, new object[1] { ((Component)PlayerController.instance).transform.position });
			Debug.Log((object)"Send message");
		}
		else
		{
			TP_SoundHandler component = ((Component)PlayerController.instance).gameObject.GetComponent<TP_SoundHandler>();
			component.RPC_PlayTPSoundArrive(((Component)PlayerController.instance).transform.position);
		}
	}

	[IteratorStateMachine(typeof(<Load>d__7))]
	private IEnumerator Load(string path, Action<AudioClip> onLoaded)
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <Load>d__7(0)
		{
			<>4__this = this,
			path = path,
			onLoaded = onLoaded
		};
	}

	public Vector3 GetRandomPosition(bool isForce = false)
	{
		//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_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Unknown result type (might be due to invalid IL or missing references)
		//IL_006d: 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)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_006f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0070: 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)
		Vector3 zero = Vector3.zero;
		if (!ConfigManager.UseMinDistWithOtherPlayer.Value || isForce)
		{
			List<LevelPoint> list = SemiFunc.LevelPointsGetAll();
			int index = Random.Range(0, list.Count);
			return ((Component)list[index]).transform.position;
		}
		return ((Component)SemiFunc.LevelPointGetFurthestFromPlayer(((Component)PlayerController.instance).transform.position, (float)ConfigManager.MinDist.Value)).transform.position;
	}
}
[HarmonyPatch(typeof(PhysGrabber))]
[HarmonyPatch("StartGrabbingPhysObject")]
public class PhysGrabber_StartGrabbing_Patch
{
	public static Random_TP random_tp;

	private static void Postfix(RaycastHit hit, PhysGrabObject _physGrabObject, PhysGrabber __instance)
	{
		//IL_009f: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dd: 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_015e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0196: Unknown result type (might be due to invalid IL or missing references)
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		if (!((ConfigEntryBase)ConfigManager.IsEnable).BoxedValue.Equals(true) || !((Object)(object)_physGrabObject != (Object)null))
		{
			return;
		}
		ValuableObject componentInParent = ((Component)_physGrabObject).GetComponentInParent<ValuableObject>();
		if (!((Object)(object)componentInParent != (Object)null))
		{
			return;
		}
		int num = Random.Range(1, 101);
		Debug.Log((object)("Nb generate : " + num + " value : " + ConfigManager.Proba.Value));
		if (num > ConfigManager.Proba.Value)
		{
			return;
		}
		Vector3 randomPosition = random_tp.GetRandomPosition();
		bool flag = false;
		while (!flag)
		{
			Enemy val = SemiFunc.EnemyGetNearest(randomPosition, (float)ConfigManager.DistanceFromEnemy.Value, true);
			if ((Object)(object)val == (Object)null)
			{
				flag = true;
				continue;
			}
			randomPosition = random_tp.GetRandomPosition(isForce: true);
			Debug.Log((object)"Try found new pos");
		}
		__instance.ReleaseObject(__instance.photonView.ViewID, 0.1f);
		if ((Object)(object)random_tp != (Object)null)
		{
			Debug.Log((object)"Call send sound");
			random_tp.PlayTPSoundLeaveNetworked();
			Debug.Log((object)"End send message");
		}
		else
		{
			Debug.LogError((object)"random tp not set");
		}
		((Component)PlayerController.instance).GetComponent<Rigidbody>().position = randomPosition;
		Debug.Log((object)"Call send sound");
		random_tp.PlayTPSoundArriveNetworked();
		Debug.Log((object)"End send message");
		Vector3 position = ((Component)PlayerController.instance).transform.position;
		Debug.Log((object)("TP to : " + ((object)(Vector3)(ref position)).ToString()));
	}
}
[HarmonyPatch]
public class PlayerController_Awake_Patch
{
	private static MethodBase TargetMethod()
	{
		return AccessTools.Method(typeof(PlayerController), "Awake", (Type[])null, (Type[])null);
	}

	private static void Postfix(PlayerController __instance)
	{
		if (!((Object)(object)__instance == (Object)null))
		{
			TP_SoundHandler component = ((Component)__instance).gameObject.GetComponent<TP_SoundHandler>();
			if ((Object)(object)component == (Object)null)
			{
				component = ((Component)__instance).gameObject.AddComponent<TP_SoundHandler>();
				component.tpSoundLeave = Random_TP.tpSoundLeave;
				component.tpSoundArrive = Random_TP.tpSoundArrive;
			}
			Debug.Log((object)"[TP] TP_SoundHandler attached via AccessTools");
		}
	}
}
public class TP_SoundHandler : MonoBehaviourPun
{
	public AudioClip tpSoundLeave = null;

	public AudioClip tpSoundArrive = null;

	[PunRPC]
	public void RPC_PlayTPSoundLeave(Vector3 position)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		if (ConfigManager.EnableTPSound.Value)
		{
			Debug.Log((object)"Start play sound");
			if ((Object)(object)tpSoundLeave == (Object)null)
			{
				Debug.LogError((object)"leave sound not set");
			}
			else
			{
				AudioSource.PlayClipAtPoint(tpSoundLeave, position);
			}
			Debug.Log((object)"End play sound");
		}
	}

	[PunRPC]
	public void RPC_PlayTPSoundArrive(Vector3 position)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		if (ConfigManager.EnableTPSound.Value)
		{
			Debug.Log((object)"Start play sound");
			if ((Object)(object)tpSoundLeave == (Object)null)
			{
				Debug.LogError((object)"leave sound not set");
			}
			else
			{
				AudioSource.PlayClipAtPoint(tpSoundArrive, position);
			}
			Debug.Log((object)"End play sound");
		}
	}
}
namespace config;

internal static class ConfigManager
{
	public static ConfigFile ConfigFile { get; private set; }

	public static ConfigEntry<bool> IsEnable { get; private set; }

	public static ConfigEntry<int> Proba { get; private set; }

	public static ConfigEntry<bool> UseMinDistWithOtherPlayer { get; private set; }

	public static ConfigEntry<int> MinDist { get; private set; }

	public static ConfigEntry<bool> EnableTPSound { get; private set; }

	public static ConfigEntry<int> DistanceFromEnemy { get; private set; }

	public static void Initialize(ConfigFile configFile)
	{
		ConfigFile = configFile;
		BindConfigs();
	}

	private static void BindConfigs()
	{
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_004d: Expected O, but got Unknown
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a0: Expected O, but got Unknown
		//IL_00e8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f2: Expected O, but got Unknown
		IsEnable = ConfigFile.Bind<bool>("General", "Enable", true, "Enable random tp.");
		Proba = ConfigFile.Bind<int>("General", "Probability of random tp", 1, new ConfigDescription("Probability to tp when you grap an object", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		UseMinDistWithOtherPlayer = ConfigFile.Bind<bool>("General", "Use minimum distance from other player when tp", false, "Use minimum distance from other player when tp.");
		MinDist = ConfigFile.Bind<int>("General", "Min dist", 14, new ConfigDescription("Min distance", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 100), Array.Empty<object>()));
		EnableTPSound = ConfigFile.Bind<bool>("General", "Enable TP Sound", true, "Enable tp sound.");
		DistanceFromEnemy = ConfigFile.Bind<int>("General", "Distance from enemy", 5, new ConfigDescription("Distance from enemy when tp.", (AcceptableValueBase)(object)new AcceptableValueRange<int>(0, 25), Array.Empty<object>()));
	}
}