Decompiled source of Damage Swap v1.1.0

JellyJamLocationSwapPEAKMod.dll

Decompiled 3 days ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using HarmonyLib;
using JellyJamLocationSwapPEAKMod;
using JellyJamTinyPeakMod.Patches;
using Photon.Pun;
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("JellyJamLocationSwapPEAKMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("JellyJamLocationSwapPEAKMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("d300a51b-4145-4301-b462-e7e308614952")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
public class RandomDamageTeleport : MonoBehaviour
{
	private CharacterAfflictions _afflictions;

	private static float lastSwapTime;

	private void Awake()
	{
		_afflictions = ((Component)this).GetComponent<CharacterAfflictions>();
		if ((Object)(object)_afflictions != (Object)null)
		{
			CharacterAfflictions afflictions = _afflictions;
			afflictions.OnAddedStatus = (Action<STATUSTYPE, float>)Delegate.Combine(afflictions.OnAddedStatus, new Action<STATUSTYPE, float>(OnStatusAdded));
		}
	}

	private void OnStatusAdded(STATUSTYPE status, float value)
	{
		//IL_0021: 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_006b: Expected I4, but got Unknown
		Character component = ((Component)this).GetComponent<Character>();
		if (!((Object)(object)component == (Object)null))
		{
			if (PhotonNetwork.IsMasterClient)
			{
				TrySwap(component, status, value);
			}
			else if ((Object)(object)((MonoBehaviourPun)component).photonView != (Object)null)
			{
				((MonoBehaviourPun)component).photonView.RPC("RequestSwapFromClient", (RpcTarget)2, new object[3]
				{
					((MonoBehaviourPun)component).photonView.ViewID,
					(int)status,
					value
				});
			}
		}
	}

	[PunRPC]
	public void RequestSwapFromClient(int viewId, int statusInt, float amount)
	{
		if (!PhotonNetwork.IsMasterClient)
		{
			return;
		}
		PhotonView val = PhotonView.Find(viewId);
		if (!((Object)(object)val == (Object)null))
		{
			Character component = ((Component)val).GetComponent<Character>();
			if (!((Object)(object)component == (Object)null))
			{
				TrySwap(component, (STATUSTYPE)statusInt, amount);
			}
		}
	}

	private void TrySwap(Character selfChar, STATUSTYPE status, float value)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0040: Invalid comparison between Unknown and I4
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Invalid comparison between Unknown and I4
		//IL_007c: Unknown result type (might be due to invalid IL or missing references)
		//IL_007e: Invalid comparison between Unknown and I4
		//IL_009b: Unknown result type (might be due to invalid IL or missing references)
		//IL_009d: Invalid comparison between Unknown and I4
		//IL_00ba: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bc: Invalid comparison between Unknown and I4
		//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00dc: Invalid comparison between Unknown and I4
		//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
		//IL_0117: Unknown result type (might be due to invalid IL or missing references)
		//IL_011a: Invalid comparison between Unknown and I4
		//IL_0137: Unknown result type (might be due to invalid IL or missing references)
		//IL_0139: Invalid comparison between Unknown and I4
		//IL_0156: Unknown result type (might be due to invalid IL or missing references)
		//IL_0158: Invalid comparison between Unknown and I4
		if (!SwapDamageConfig.IsEnabled.Value || value < SwapDamageConfig.MinimumAmount.Value || ((int)status == 1 && !SwapDamageConfig.ToggleHunger.Value) || ((int)status == 7 && !SwapDamageConfig.ToggleWeight.Value) || ((int)status == 3 && !SwapDamageConfig.TogglePoison.Value) || ((int)status == 8 && !SwapDamageConfig.ToggleHot.Value) || ((int)status == 2 && !SwapDamageConfig.ToggleCold.Value) || ((int)status == 10 && !SwapDamageConfig.ToggleSpores.Value) || ((int)status == 0 && !SwapDamageConfig.ToggleInjury.Value) || ((int)status == 9 && !SwapDamageConfig.ToggleThorns.Value) || ((int)status == 6 && !SwapDamageConfig.ToggleDrowsy.Value) || ((int)status == 5 && !SwapDamageConfig.ToggleCurse.Value) || Time.time - lastSwapTime < SwapDamageConfig.SwapCooldown.Value)
		{
			return;
		}
		IEnumerable<Character> source = (SwapDamageConfig.AllowCarried.Value ? (from c in Character.AllCharacters
			where (Object)(object)c != (Object)null
			where (Object)(object)c != (Object)(object)selfChar
			where (Object)(object)c.data != (Object)null
			where !c.data.dead
			select c) : (from c in Character.AllCharacters
			where (Object)(object)c != (Object)null
			where (Object)(object)c != (Object)(object)selfChar
			where (Object)(object)c.data != (Object)null
			where !c.data.dead
			where !c.data.isCarried
			select c));
		Character[] array = source.ToArray();
		if (array.Length == 0)
		{
			return;
		}
		Character val = array[Random.Range(0, array.Length)];
		if (SwapDamageConfig.DropCarryOnTeleport.Value)
		{
			if (selfChar.data.IsCarryingCharacter)
			{
				selfChar.refs.carriying.Drop(selfChar.data.carriedPlayer);
			}
			if (val.data.IsCarryingCharacter)
			{
				val.refs.carriying.Drop(val.data.carriedPlayer);
			}
		}
		SwapWith(selfChar, val);
		lastSwapTime = Time.time;
	}

	private void SwapWith(Character selfChar, Character target)
	{
		//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_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_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_008d: Unknown result type (might be due to invalid IL or missing references)
		if (!((Object)(object)selfChar == (Object)null) && !((Object)(object)target == (Object)null) && !selfChar.data.dead && !target.data.dead)
		{
			Vector3 center = selfChar.Center;
			Vector3 center2 = target.Center;
			((MonoBehaviourPun)selfChar).photonView.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2] { center2, false });
			((MonoBehaviourPun)target).photonView.RPC("WarpPlayerRPC", (RpcTarget)0, new object[2] { center, false });
			Debug.Log((object)("[RandomDamageTeleport] Swapped " + ((Object)selfChar).name + " with " + ((Object)target).name));
		}
	}
}
namespace JellyJamTinyPeakMod.Patches
{
	[HarmonyPatch(typeof(Character))]
	public class AfflictionPatch
	{
		[HarmonyPatch("Awake")]
		[HarmonyPostfix]
		public static void AwakePostfix(Character __instance)
		{
			if (!((Object)(object)__instance == (Object)null) && (Object)(object)((Component)__instance).GetComponent<RandomDamageTeleport>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<RandomDamageTeleport>();
			}
		}
	}
}
namespace JellyJamLocationSwapPEAKMod
{
	[BepInPlugin("JellyJam.LocationSwapMod", "JellyJamLocationSwapMod", "1.0.0.0")]
	public class ModBase : BaseUnityPlugin
	{
		private const string modGUID = "JellyJam.LocationSwapMod";

		private const string modName = "JellyJamLocationSwapMod";

		private const string modVersion = "1.0.0.0";

		private readonly Harmony harmony = new Harmony("JellyJam.LocationSwapMod");

		private static ModBase Instance;

		internal ManualLogSource mls;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("JellyJam.LocationSwapMod");
			SwapDamageConfig.Initialize((BaseUnityPlugin)(object)this);
			mls.LogInfo((object)"The JellyJamLocationSwapMod has started");
			harmony.PatchAll();
		}
	}
	internal static class SwapDamageConfig
	{
		internal static ManualLogSource Logger;

		internal static ConfigEntry<bool> IsEnabled;

		internal static ConfigEntry<bool> TogglePoison;

		internal static ConfigEntry<bool> ToggleHot;

		internal static ConfigEntry<bool> ToggleCold;

		internal static ConfigEntry<bool> ToggleCurse;

		internal static ConfigEntry<bool> ToggleSpores;

		internal static ConfigEntry<bool> ToggleInjury;

		internal static ConfigEntry<bool> ToggleThorns;

		internal static ConfigEntry<bool> ToggleHunger;

		internal static ConfigEntry<bool> ToggleWeight;

		internal static ConfigEntry<bool> ToggleDrowsy;

		internal static ConfigEntry<bool> AllowCarried;

		internal static ConfigEntry<bool> DropCarryOnTeleport;

		internal static ConfigEntry<float> SwapCooldown;

		internal static ConfigEntry<float> MinimumAmount;

		private static Harmony _harmony;

		internal static void Initialize(BaseUnityPlugin plugin)
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			Logger = Logger.CreateLogSource("SwapDamageConfig");
			BindConfig(plugin);
			if (_harmony == null)
			{
				_harmony = new Harmony("JellyJam.LocationSwapMod.Config");
				_harmony.PatchAll(typeof(AfflictionPatch));
			}
			Logger.LogInfo((object)"SwapDamageConfig initialized");
		}

		private static void BindConfig(BaseUnityPlugin plugin)
		{
			IsEnabled = plugin.Config.Bind<bool>("General", "GlobalEnable", true, "Mod enabled state.");
			ToggleCurse = plugin.Config.Bind<bool>("StatusTypes", "CurseEnabled", false, "Should this status cause a teleport?");
			ToggleHunger = plugin.Config.Bind<bool>("StatusTypes", "HungerEnabled", false, "Should this status cause a teleport?");
			ToggleWeight = plugin.Config.Bind<bool>("StatusTypes", "WeightEnabled", false, "Should this status cause a teleport?");
			TogglePoison = plugin.Config.Bind<bool>("StatusTypes", "PoisonEnabled", true, "Should this status cause a teleport?");
			ToggleHot = plugin.Config.Bind<bool>("StatusTypes", "HotEnabled", true, "Should this status cause a teleport?");
			ToggleCold = plugin.Config.Bind<bool>("StatusTypes", "ColdEnabled", true, "Should this status cause a teleport?");
			ToggleSpores = plugin.Config.Bind<bool>("StatusTypes", "SporesEnabled", true, "Should this status cause a teleport?");
			ToggleInjury = plugin.Config.Bind<bool>("StatusTypes", "InjuryEnabled", true, "Should this status cause a teleport?");
			ToggleThorns = plugin.Config.Bind<bool>("StatusTypes", "ThornsEnabled", true, "Should this status cause a teleport?");
			ToggleDrowsy = plugin.Config.Bind<bool>("StatusTypes", "DrowsyEnabled", true, "Should this status cause a teleport?");
			AllowCarried = plugin.Config.Bind<bool>("General", "AllowCarriedTeleports", true, "Whether or not carried players are affected by teleporter events.");
			DropCarryOnTeleport = plugin.Config.Bind<bool>("General", "DropCarryOnTeleport", true, "Whether or not carried players are dropped when the player holding them is teleported.");
			SwapCooldown = plugin.Config.Bind<float>("General", "SwapCooldown", 2f, "Delay between allowed teleport events per user.");
			MinimumAmount = plugin.Config.Bind<float>("General", "MinimumAmount", 0f, "Minimum amount of status required to trigger a teleport.");
		}
	}
}