Decompiled source of CortisolMod v1.0.0

plugins/CortisolMod.dll

Decompiled 13 hours ago
using System;
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 HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
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("REPOMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("REPOMod")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("9d5803c9-89ab-4ae8-b919-6186cfb4b222")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyVersion("1.0.0.0")]
[HarmonyPatch(typeof(PlayerController), "Update")]
public static class CortisolPatch
{
	private static float cortisolLevel = 0f;

	private static float cortisolMax = 100f;

	private static FieldInfo fieldPlayerClose = typeof(EnemyParent).GetField("playerClose", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static FieldInfo fieldPlayerVeryClose = typeof(EnemyParent).GetField("playerVeryClose", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static FieldInfo fieldEnemy = typeof(EnemyParent).GetField("Enemy", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static FieldInfo fieldVisionMask = typeof(Enemy).GetField("VisionMask", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static FieldInfo fieldTargetPlayerAvatar = typeof(Enemy).GetField("TargetPlayerAvatar", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static FieldInfo fieldChromaticAberration = typeof(PostProcessing).GetField("chromaticAberration", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static FieldInfo fieldPlayerTumble = typeof(PlayerAvatar).GetField("tumble", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);

	private static EnemyParent[] enemies = (EnemyParent[])(object)new EnemyParent[0];

	private static float refreshTimer = 0f;

	private static float sawTimer = 0f;

	private static bool saw = false;

	private static float sawTimerMax = 5f;

	private static float playerVision = 13f;

	private static void Postfix(PlayerController __instance)
	{
		//IL_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
		//IL_00d4: Invalid comparison between Unknown and I4
		//IL_0153: Unknown result type (might be due to invalid IL or missing references)
		//IL_015a: Expected O, but got Unknown
		//IL_015c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0162: Invalid comparison between Unknown and I4
		//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Invalid comparison between Unknown and I4
		//IL_0166: Unknown result type (might be due to invalid IL or missing references)
		//IL_016c: Invalid comparison between Unknown and I4
		//IL_010a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0111: Invalid comparison between Unknown and I4
		//IL_0170: Unknown result type (might be due to invalid IL or missing references)
		//IL_0176: Invalid comparison between Unknown and I4
		//IL_0115: Unknown result type (might be due to invalid IL or missing references)
		//IL_011c: Invalid comparison between Unknown and I4
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0127: Invalid comparison between Unknown and I4
		//IL_012b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Invalid comparison between Unknown and I4
		if ((Object)(object)__instance == (Object)null)
		{
			return;
		}
		refreshTimer -= Time.deltaTime;
		if (refreshTimer <= 0f)
		{
			enemies = Object.FindObjectsOfType<EnemyParent>();
			refreshTimer = 1f;
		}
		float num = 0f;
		float num2 = 0f;
		bool flag = false;
		EnemyParent[] array = enemies;
		foreach (EnemyParent val in array)
		{
			if ((Object)(object)val == (Object)null)
			{
				continue;
			}
			bool flag2 = checkIfHarmless(val);
			Enemy val2 = (Enemy)fieldEnemy.GetValue(val);
			if ((Object)(object)val2 == (Object)null)
			{
				continue;
			}
			EnemyAnimal componentInChildren = ((Component)val).GetComponentInChildren<EnemyAnimal>();
			if ((Object)(object)componentInChildren != (Object)null && (int)componentInChildren.currentState != 6)
			{
				continue;
			}
			EnemyDuck componentInChildren2 = ((Component)val).GetComponentInChildren<EnemyDuck>();
			if (!((Object)(object)componentInChildren2 != (Object)null) || (int)componentInChildren2.currentState == 12 || (int)componentInChildren2.currentState == 13 || (int)componentInChildren2.currentState == 14 || (int)componentInChildren2.currentState == 15 || (int)componentInChildren2.currentState == 11)
			{
				PlayerAvatar val3 = (PlayerAvatar)fieldTargetPlayerAvatar.GetValue(val2);
				bool flag3 = ((int)val2.CurrentState == 3 || (int)val2.CurrentState == 4 || (int)val2.CurrentState == 5) && (Object)(object)val3 == (Object)(object)PlayerController.instance.playerAvatarScript;
				bool flag4 = (bool)fieldPlayerVeryClose.GetValue(val);
				bool flag5 = (bool)fieldPlayerClose.GetValue(val);
				bool flag6 = PlayerCanSeeEnemy(__instance, val);
				if (flag3 && !flag2)
				{
					num = Mathf.Max(num, 100f);
					num2 = Mathf.Max(num2, 6f);
					flag = true;
				}
				else if (flag4 && flag6 && !flag2)
				{
					num = Mathf.Max(num, 100f);
					num2 = Mathf.Max(num2, 4f);
					flag = true;
				}
				else if (flag5 && flag6 && !flag2)
				{
					num = Mathf.Max(num, 100f);
					num2 = Mathf.Max(num2, 1f);
					flag = true;
				}
				else if (flag5 && flag6 && flag2)
				{
					num = Mathf.Max(num, 100f);
					num2 = Mathf.Max(num2, 1f);
					flag = true;
				}
				else if (flag6)
				{
					num = Mathf.Max(num, 100f);
					num2 = Mathf.Max(num2, 1f);
					flag = true;
				}
			}
		}
		if (flag)
		{
			saw = true;
			sawTimer = sawTimerMax;
		}
		else
		{
			sawTimer -= Time.deltaTime;
			if (sawTimer <= 0f)
			{
				saw = false;
			}
		}
		if (saw && cortisolLevel < num)
		{
			cortisolLevel += Time.deltaTime * num2;
		}
		else if (!saw)
		{
			cortisolLevel -= Time.deltaTime * 2f;
		}
		cortisolLevel = Mathf.Clamp(cortisolLevel, 0f, cortisolMax);
		CortisolUI.UpdateValue(cortisolLevel);
		ApplyEffects(__instance);
	}

	private static void ApplyEffects(PlayerController __instance)
	{
		//IL_0042: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ea: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: 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_00f8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00fb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0161: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Expected O, but got Unknown
		float num = cortisolLevel / cortisolMax;
		if (num > 0.25f)
		{
			SemiFunc.CameraShake(num * 4f, 2f);
		}
		if (num >= 0.5f)
		{
			PostProcessing.Instance.VignetteOverride(Color.red, num, 0.5f, 0.5f, 0.5f, 0.2f, (GameObject)null);
			ApplyChromaticAberration(num);
			MusicEnemyNear instance = MusicEnemyNear.instance;
			if (instance != null)
			{
				instance.OverrideActive(num);
			}
		}
		else
		{
			ApplyChromaticAberration(0f);
			MusicEnemyNear instance2 = MusicEnemyNear.instance;
			if (instance2 != null)
			{
				instance2.OverrideActive(0f);
			}
		}
		if (num >= 0.7f && Random.Range(0, 800) < 2)
		{
			Vector3 val = new Vector3(Random.Range(-1f, 1f), 0f, Random.Range(-1f, 1f));
			Vector3 normalized = ((Vector3)(ref val)).normalized;
			__instance.MoveForce(normalized, 3f * num, 0.3f);
		}
		if (num >= 0.8f)
		{
			__instance.OverrideVoicePitch(1.5f, 0.1f, 0.1f, 0.5f);
		}
		if (num >= 1f)
		{
			PlayerTumble val2 = (PlayerTumble)fieldPlayerTumble.GetValue(__instance.playerAvatarScript);
			val2.TumbleRequest(true, false);
			cortisolLevel = 0f;
		}
	}

	private static bool PlayerCanSeeEnemy(PlayerController player, EnemyParent enemyParent)
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Expected O, but got Unknown
		//IL_0027: Unknown result type (might be due to invalid IL or missing references)
		Enemy val = (Enemy)fieldEnemy.GetValue(enemyParent);
		if ((Object)(object)val == (Object)null)
		{
			return false;
		}
		return SemiFunc.PlayerVisionCheck(val.CenterTransform.position, playerVision, player.playerAvatarScript, false);
	}

	private static void ApplyChromaticAberration(float percent)
	{
		if ((Object)(object)PostProcessing.Instance == (Object)null)
		{
			return;
		}
		object value = fieldChromaticAberration.GetValue(PostProcessing.Instance);
		if (value != null)
		{
			PropertyInfo property = value.GetType().GetProperty("intensity");
			if (property != null)
			{
				object value2 = property.GetValue(value);
				value2.GetType().GetProperty("value")?.SetValue(value2, percent * 0.5f);
			}
		}
	}

	private static bool checkIfHarmless(EnemyParent enemyParent)
	{
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004b: Invalid comparison between Unknown and I4
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Invalid comparison between Unknown and I4
		//IL_0057: Unknown result type (might be due to invalid IL or missing references)
		//IL_005e: Invalid comparison between Unknown and I4
		//IL_0061: Unknown result type (might be due to invalid IL or missing references)
		//IL_0068: Invalid comparison between Unknown and I4
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0072: Invalid comparison between Unknown and I4
		//IL_0075: Unknown result type (might be due to invalid IL or missing references)
		//IL_007c: Invalid comparison between Unknown and I4
		//IL_007f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Invalid comparison between Unknown and I4
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Invalid comparison between Unknown and I4
		bool result = false;
		EnemyGnome componentInChildren = ((Component)enemyParent).GetComponentInChildren<EnemyGnome>();
		if ((Object)(object)componentInChildren != (Object)null)
		{
			result = true;
		}
		EnemyTick componentInChildren2 = ((Component)enemyParent).GetComponentInChildren<EnemyTick>();
		if ((Object)(object)componentInChildren2 != (Object)null)
		{
			result = true;
		}
		EnemyBirthdayBoy componentInChildren3 = ((Component)enemyParent).GetComponentInChildren<EnemyBirthdayBoy>();
		if ((Object)(object)componentInChildren3 != (Object)null && (int)componentInChildren3.currentState != 6 && (int)componentInChildren3.currentState != 7 && (int)componentInChildren3.currentState != 13 && (int)componentInChildren3.currentState != 14 && (int)componentInChildren3.currentState != 15 && (int)componentInChildren3.currentState != 16 && (int)componentInChildren3.currentState != 18 && (int)componentInChildren3.currentState != 10)
		{
			result = true;
		}
		return result;
	}

	public static void ResetCortisolLevel()
	{
		cortisolLevel = 0f;
	}
}
public static class CortisolUI
{
	private static GameObject cortisolUIObj;

	private static TextMeshProUGUI cortisolText;

	private static Sprite cortisolIcon;

	public static void Create()
	{
		//IL_0048: Unknown result type (might be due to invalid IL or missing references)
		//IL_004e: Invalid comparison between Unknown and I4
		//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
		//IL_0150: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)EnergyUI.instance == (Object)null || (Object)(object)PlayerController.instance == (Object)null || (Object)(object)GameDirector.instance == (Object)null || (int)GameDirector.instance.currentState != 2)
		{
			return;
		}
		GameObject gameObject = ((Component)EnergyUI.instance).gameObject;
		cortisolUIObj = Object.Instantiate<GameObject>(gameObject, gameObject.transform.parent);
		((Object)cortisolUIObj).name = "CortisolUI";
		Object.Destroy((Object)(object)cortisolUIObj.GetComponent<EnergyUI>());
		RectTransform component = cortisolUIObj.GetComponent<RectTransform>();
		component.anchoredPosition += new Vector2(0f, -40f);
		cortisolText = cortisolUIObj.GetComponent<TextMeshProUGUI>();
		((Graphic)cortisolText).color = new Color(1f, 0.4f, 0f);
		Transform val = cortisolUIObj.transform.Find("EnergyMax");
		if ((Object)(object)val != (Object)null)
		{
			TextMeshProUGUI component2 = ((Component)val).GetComponent<TextMeshProUGUI>();
			if ((Object)(object)component2 != (Object)null)
			{
				((TMP_Text)component2).text = "<b><color=orange>/</color></b>100";
			}
			((Graphic)component2).color = new Color(1f, 0.4f, 0f);
		}
		Transform val2 = cortisolUIObj.transform.Find("Zap");
		if ((Object)(object)val2 != (Object)null && (Object)(object)cortisolIcon != (Object)null)
		{
			Image component3 = ((Component)val2).GetComponent<Image>();
			if ((Object)(object)component3 != (Object)null)
			{
				component3.sprite = cortisolIcon;
			}
		}
	}

	public static bool IsCreated()
	{
		return (Object)(object)cortisolUIObj != (Object)null && (Object)(object)cortisolText != (Object)null;
	}

	public static void UpdateValue(float cortisolLevel)
	{
		if (!((Object)(object)cortisolText == (Object)null))
		{
			((TMP_Text)cortisolText).text = Mathf.CeilToInt(cortisolLevel).ToString();
		}
	}

	public static void LoadBundle()
	{
		string text = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "cortisolicons");
		AssetBundle val = AssetBundle.LoadFromFile(text);
		if ((Object)(object)val == (Object)null)
		{
			Debug.Log((object)"[CortisolUI] Bundle introuvable !");
			return;
		}
		cortisolIcon = val.LoadAsset<Sprite>("exclamation");
		val.Unload(false);
		Debug.Log((object)"[CortisolUI] Bundle chargé !");
	}

	private static void DumpChildren(Transform parent, int depth)
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0025: Expected O, but got Unknown
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: 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_013d: Unknown result type (might be due to invalid IL or missing references)
		string text = new string('-', depth * 2);
		foreach (Transform item in parent)
		{
			Transform val = item;
			Debug.Log((object)("[Dump] " + text + " Child: " + ((Object)val).name));
			Component[] components = ((Component)val).GetComponents<Component>();
			foreach (Component val2 in components)
			{
				Debug.Log((object)("[Dump] " + text + "   Component: " + ((object)val2).GetType().Name));
				TextMeshProUGUI val3 = (TextMeshProUGUI)(object)((val2 is TextMeshProUGUI) ? val2 : null);
				if (val3 != null)
				{
					Debug.Log((object)$"[Dump] {text}     text: '{((TMP_Text)val3).text}' | fontSize: {((TMP_Text)val3).fontSize} | color: {((Graphic)val3).color}");
				}
				RectTransform val4 = (RectTransform)(object)((val2 is RectTransform) ? val2 : null);
				if (val4 != null)
				{
					Debug.Log((object)$"[Dump] {text}     anchoredPos: {val4.anchoredPosition} | size: {val4.sizeDelta}");
				}
				Image val5 = (Image)(object)((val2 is Image) ? val2 : null);
				if (val5 != null)
				{
					Sprite sprite = val5.sprite;
					Debug.Log((object)$"[Dump] {text}     sprite: {((sprite != null) ? ((Object)sprite).name : null)} | color: {((Graphic)val5).color}");
				}
			}
			DumpChildren(val, depth + 1);
		}
	}
}
[HarmonyPatch(typeof(EnemyVision), "VisionTrigger")]
public static class DisableEnemyVisionPatch
{
}
public class StarterModHandler : MonoBehaviour
{
	private bool levelInitialized = false;

	private object levelGeneratorInstance = null;

	private Type levelGeneratorType = null;

	private void Update()
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_008f: Invalid comparison between Unknown and I4
		if (!levelInitialized && TryGetLevelGeneratorInstance(out levelGeneratorInstance, out levelGeneratorType))
		{
			FieldInfo field = levelGeneratorType.GetField("Generated", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (field != null && (bool)field.GetValue(levelGeneratorInstance))
			{
				levelInitialized = true;
			}
		}
		if (levelInitialized && !CortisolUI.IsCreated() && (Object)(object)EnergyUI.instance != (Object)null)
		{
			GameDirector instance = GameDirector.instance;
			if (instance != null && (int)instance.currentState == 2)
			{
				CortisolUI.Create();
			}
		}
	}

	private void LogKeyInputs()
	{
		//IL_001f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0024: Unknown result type (might be due to invalid IL or missing references)
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0036: Unknown result type (might be due to invalid IL or missing references)
		foreach (KeyCode value in Enum.GetValues(typeof(KeyCode)))
		{
			if (Input.GetKeyDown(value))
			{
				Debug.Log((object)$"[StarterMod] Key pressed: {(object)value}");
			}
		}
	}

	private bool TryGetLevelGeneratorInstance(out object instance, out Type type)
	{
		type = AppDomain.CurrentDomain.GetAssemblies().SelectMany((Assembly a) => a.GetTypes()).FirstOrDefault((Type t) => t.Name == "LevelGenerator");
		if (type != null)
		{
			instance = Object.FindObjectOfType(type);
			return instance != null;
		}
		instance = null;
		return false;
	}
}
[BepInPlugin("com.yourname.repostarter", "REPO Starter Mod", "1.0.0")]
public class StarterPlugin : BaseUnityPlugin
{
	private void Awake()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_000c: Expected O, but got Unknown
		Harmony val = new Harmony("com.yourname.repostarter");
		val.PatchAll();
		SceneManager.sceneLoaded += OnSceneLoaded;
		CortisolUI.LoadBundle();
	}

	private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
	{
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Expected O, but got Unknown
		((BaseUnityPlugin)this).Logger.LogInfo((object)("[StarterMod] Scene loaded: " + ((Scene)(ref scene)).name));
		CortisolPatch.ResetCortisolLevel();
		if ((Object)(object)GameObject.Find("StarterModHandler") == (Object)null)
		{
			GameObject val = new GameObject("StarterModHandler");
			val.AddComponent<StarterModHandler>();
			Object.DontDestroyOnLoad((Object)(object)val);
		}
	}
}
[HarmonyPatch(typeof(ValuableDirector), "Spawn")]
public static class ValuableLoggerPatch
{
}