Decompiled source of TandamOneRule v1.0.0

BepInEx\plugins\TandamOneRule\aTandamOneRule.dll

Decompiled 3 hours ago
using System;
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 HarmonyLib;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("aTandamOneRule")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("aTandamOneRule")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cfb322d6-385c-4228-beb2-db5f44b2fdd6")]
[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")]
[BepInPlugin("tandam.onerule", "Tandam One Rule", "1.0.0")]
public class TandamOneRule : BaseUnityPlugin
{
	private enum Rule
	{
		EnemyHPDouble,
		EnemyHPHalf,
		EnemySpeedDouble,
		EnemySpeedSlow,
		PlayerSpeedDouble,
		PlayerSpeedSlow,
		ItemValueDouble,
		ItemValueLow
	}

	[HarmonyPatch(typeof(RunManager), "ChangeLevel")]
	public static class RunManager_ChangeLevel_Patch
	{
		private static void Prefix()
		{
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				SelectRandomRule();
				Debug.Log((object)"================================");
				Debug.Log((object)("[Tandam One Rule] NEW LEVEL RULE: " + GetRuleDisplayNameStatic()));
				Debug.Log((object)"================================");
			}
		}
	}

	[HarmonyPatch(typeof(EnemyHealth), "OnSpawn")]
	public static class EnemyHealth_OnSpawn_Patch
	{
		private static readonly HashSet<EnemyHealth> applied = new HashSet<EnemyHealth>();

		private static void Prefix(EnemyHealth __instance)
		{
			if (SemiFunc.IsMasterClientOrSingleplayer() && !((Object)(object)__instance == (Object)null) && !applied.Contains(__instance))
			{
				applied.Add(__instance);
				if (selectedRule == Rule.EnemyHPDouble)
				{
					__instance.health = Mathf.Max(1, Mathf.RoundToInt((float)__instance.health * 2f));
					Debug.Log((object)"[Tandam One Rule] Enemy HP x2");
				}
				else if (selectedRule == Rule.EnemyHPHalf)
				{
					__instance.health = Mathf.Max(1, Mathf.RoundToInt((float)__instance.health * 0.5f));
					Debug.Log((object)"[Tandam One Rule] Enemy HP x0.5");
				}
			}
		}
	}

	[HarmonyPatch(typeof(Enemy), "Spawn")]
	public static class Enemy_Spawn_Patch
	{
		private static readonly HashSet<Enemy> applied = new HashSet<Enemy>();

		private static void Postfix(Enemy __instance)
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer() || (Object)(object)__instance == (Object)null || applied.Contains(__instance))
			{
				return;
			}
			applied.Add(__instance);
			if (selectedRule != Rule.EnemySpeedDouble && selectedRule != Rule.EnemySpeedSlow)
			{
				return;
			}
			EnemyNavMeshAgent component = ((Component)__instance).GetComponent<EnemyNavMeshAgent>();
			if ((Object)(object)component == (Object)null)
			{
				Debug.Log((object)"[Tandam One Rule] EnemyNavMeshAgent not found.");
				return;
			}
			NavMeshAgent component2 = ((Component)component).GetComponent<NavMeshAgent>();
			if ((Object)(object)component2 == (Object)null)
			{
				Debug.Log((object)"[Tandam One Rule] NavMeshAgent not found.");
			}
			else if (selectedRule == Rule.EnemySpeedDouble)
			{
				component2.speed *= 2f;
				Debug.Log((object)"[Tandam One Rule] Enemy Speed x2");
			}
			else if (selectedRule == Rule.EnemySpeedSlow)
			{
				component2.speed *= 0.75f;
				Debug.Log((object)"[Tandam One Rule] Enemy Speed x0.75");
			}
		}
	}

	[HarmonyPatch(typeof(PlayerController), "FixedUpdate")]
	public static class PlayerController_FixedUpdate_Patch
	{
		private static readonly Dictionary<PlayerController, float> originalSpeed = new Dictionary<PlayerController, float>();

		private static FieldInfo speedField;

		private static void Postfix(PlayerController __instance)
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer() || (Object)(object)__instance == (Object)null || (selectedRule != Rule.PlayerSpeedDouble && selectedRule != Rule.PlayerSpeedSlow))
			{
				return;
			}
			try
			{
				if (speedField == null)
				{
					speedField = FindSpeedField(((object)__instance).GetType());
				}
				if (speedField == null)
				{
					return;
				}
				if (!originalSpeed.ContainsKey(__instance))
				{
					object value = speedField.GetValue(__instance);
					if (!(value is float))
					{
						return;
					}
					originalSpeed[__instance] = (float)value;
				}
				float num = ((selectedRule == Rule.PlayerSpeedDouble) ? 2f : 0.75f);
				speedField.SetValue(__instance, originalSpeed[__instance] * num);
			}
			catch (Exception ex)
			{
				Debug.LogWarning((object)("[Tandam One Rule] Player speed error: " + ex.Message));
			}
		}

		private static FieldInfo FindSpeedField(Type type)
		{
			string[] array = new string[4] { "MoveSpeed", "moveSpeed", "movementSpeed", "speed" };
			string[] array2 = array;
			foreach (string name in array2)
			{
				FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (field != null && field.FieldType == typeof(float))
				{
					return field;
				}
			}
			return null;
		}
	}

	[HarmonyPatch(typeof(ItemAttributes), "GetValue")]
	public static class ItemAttributes_GetValue_Patch
	{
		private static readonly HashSet<ItemAttributes> applied = new HashSet<ItemAttributes>();

		private static FieldInfo valueField;

		private static void Postfix(ItemAttributes __instance)
		{
			if (!SemiFunc.IsMasterClientOrSingleplayer() || (Object)(object)__instance == (Object)null || (selectedRule != Rule.ItemValueDouble && selectedRule != Rule.ItemValueLow) || applied.Contains(__instance))
			{
				return;
			}
			applied.Add(__instance);
			try
			{
				if (valueField == null)
				{
					valueField = typeof(ItemAttributes).GetField("value", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				if (valueField == null)
				{
					Debug.LogWarning((object)"[Tandam One Rule] ItemAttributes.value not found.");
				}
				else if (valueField.GetValue(__instance) is int num)
				{
					float num2 = ((selectedRule == Rule.ItemValueDouble) ? 2f : 0.75f);
					int num3 = Mathf.Max(1, Mathf.RoundToInt((float)num * num2));
					valueField.SetValue(__instance, num3);
					Debug.Log((object)("[Tandam One Rule] Item Value " + num + " -> " + num3));
				}
			}
			catch (Exception ex)
			{
				Debug.LogError((object)("[Tandam One Rule] Item value error: " + ex.Message));
			}
		}
	}

	private static Rule selectedRule;

	private static readonly Random random = new Random();

	private void Awake()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)"================================");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Tandam One Rule loaded!");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"================================");
		SelectRandomRule();
		Harmony val = new Harmony("tandam.onerule");
		val.PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[Tandam One Rule] Harmony patches applied!");
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[Tandam One Rule] Current Rule: " + GetRuleDisplayNameStatic()));
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[Tandam One Rule] GUI TEST ENABLED");
	}

	private void Update()
	{
	}

	private void OnGUI()
	{
		//IL_0016: 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)
		try
		{
			GUI.Label(new Rect(50f, 50f, 1000f, 60f), "TANDAM ONE RULE TEST");
			GUI.Label(new Rect(50f, 100f, 1000f, 60f), "RULE: " + GetRuleDisplayNameStatic());
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("[Tandam One Rule] OnGUI Error: " + ex));
		}
	}

	private static void SelectRandomRule()
	{
		int length = Enum.GetValues(typeof(Rule)).Length;
		selectedRule = (Rule)random.Next(0, length);
		Debug.Log((object)("[Tandam One Rule] Selected Rule: " + GetRuleDisplayNameStatic()));
	}

	private static string GetRuleDisplayNameStatic()
	{
		return selectedRule switch
		{
			Rule.EnemyHPDouble => "Enemy HP x2", 
			Rule.EnemyHPHalf => "Enemy HP x0.5", 
			Rule.EnemySpeedDouble => "Enemy Speed x2", 
			Rule.EnemySpeedSlow => "Enemy Speed x0.75", 
			Rule.PlayerSpeedDouble => "Player Speed x2", 
			Rule.PlayerSpeedSlow => "Player Speed x0.75", 
			Rule.ItemValueDouble => "Item Value x2", 
			Rule.ItemValueLow => "Item Value x0.75", 
			_ => "Unknown", 
		};
	}
}