Decompiled source of RepoInGameUI v1.0.1

1.0.1/RepoInGameUI.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
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("modmenu")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("modmenu")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("86389f4a-9dc7-47ba-9a50-a625db59448a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RepoMod.Reflected;

[BepInPlugin("mylf.repo.mod.ui.reflected", "REPO In-Game UI (Reflected)", "1.0.0")]
public class RepoModUIReflected : BaseUnityPlugin
{
	private Rect _win = new Rect(40f, 40f, 460f, 560f);

	private bool _show;

	private int _healAmount = 25;

	private float _freezeSec = 3f;

	private int _batteryIndex = 0;

	private float _timeScale = 0.8f;

	private float _timeScaleDur = 1.5f;

	private float _animSpeed = 1.5f;

	private float _animIn = 6f;

	private float _animOut = 4f;

	private float _animTime = 0.1f;

	private float _staminaUi = 50f;

	private Type _tPlayerController;

	private Type _tPlayerAvatar;

	private Type _tPlayerHealth;

	private Type _tInventory;

	private Type _tEnemy;

	private FieldInfo _fPC_instance;

	private PropertyInfo _pPC_EnergyCurrent;

	private PropertyInfo _pPC_EnergyStart;

	private MethodInfo _mPC_OverrideTimeScale;

	private PropertyInfo _pPA_isLocal;

	private PropertyInfo _pPA_photonView;

	private PropertyInfo _pPV_IsMine;

	private MethodInfo _mPA_OverrideAnimationSpeed;

	private MethodInfo _mPH_Heal;

	private FieldInfo _fInv_instance;

	private MethodInfo _mInv_ForceUnequip;

	private MethodInfo _mInv_DropAll;

	private MethodInfo _mInv_GetBattery;

	private MethodInfo _mEnemy_Freeze;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[REPO][ReflectedUI] yüklendi — INSERT ile aç/kapa");
		TryWarmupReflection();
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)277))
		{
			_show = !_show;
		}
	}

	private void OnGUI()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		if (_show)
		{
			_win = GUI.Window(5356253, _win, new WindowFunction(DrawWindow), "REPO MOD PANEL (Reflected)");
		}
	}

	private void DrawWindow(int id)
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		DrawSection("Player — Health/Stamina", delegate
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Heal Amount:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(95f) });
			int.TryParse(GUILayout.TextField(_healAmount.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }), out _healAmount);
			if (GUILayout.Button("+Heal", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				HealLocal(Mathf.Max(1, _healAmount));
			}
			if (GUILayout.Button("Full Heal", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				HealLocal(999999);
			}
			GUILayout.EndHorizontal();
			object playerController = GetPlayerController();
			float num = ReadFloat(playerController, _pPC_EnergyCurrent);
			float num2 = ReadFloat(playerController, _pPC_EnergyStart);
			if (num2 <= 0f)
			{
				num2 = Mathf.Max(100f, num);
			}
			_staminaUi = Mathf.Clamp((_staminaUi <= 0f) ? num : _staminaUi, 0f, Mathf.Max(1f, num2));
			GUILayout.Label($"Stamina (EnergyCurrent): {num:0.0} / {num2:0.0}", Array.Empty<GUILayoutOption>());
			float num3 = GUILayout.HorizontalSlider(_staminaUi, 0f, Mathf.Max(1f, num2), Array.Empty<GUILayoutOption>());
			if (Math.Abs(num3 - _staminaUi) > 0.0001f)
			{
				_staminaUi = num3;
				WriteFloat(playerController, _pPC_EnergyCurrent, _staminaUi);
			}
		});
		DrawSection("Inventory", delegate
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Force Unequip", Array.Empty<GUILayoutOption>()))
			{
				ForceUnequip();
			}
			if (GUILayout.Button("Drop All", Array.Empty<GUILayoutOption>()))
			{
				DropAll();
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Battery slot:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			int.TryParse(GUILayout.TextField(_batteryIndex.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) }), out _batteryIndex);
			if (GUILayout.Button("Check", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				int battery = GetBattery(_batteryIndex);
				GUILayout.Label((battery >= 0) ? $"→ {battery}%" : "→ boş/yok", Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndHorizontal();
		});
		DrawSection("Enemies", delegate
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Freeze (sec):", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			float.TryParse(GUILayout.TextField(_freezeSec.ToString("0.0"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }), out _freezeSec);
			if (GUILayout.Button("Freeze All Visible", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) }))
			{
				FreezeAll(Mathf.Max(0.1f, _freezeSec));
			}
			GUILayout.EndHorizontal();
		});
		DrawSection("Time & Animation", delegate
		{
			_timeScale = GUILayout.HorizontalSlider(_timeScale, 0.1f, 1.5f, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"TimeScale: x{_timeScale:0.00}  dur:{_timeScaleDur:0.0}s", Array.Empty<GUILayoutOption>());
			_timeScaleDur = GUILayout.HorizontalSlider(_timeScaleDur, 0.1f, 5f, Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Apply TimeScale", Array.Empty<GUILayoutOption>()))
			{
				OverrideTimeScale(_timeScale, _timeScaleDur);
			}
			GUILayout.Space(6f);
			_animSpeed = GUILayout.HorizontalSlider(_animSpeed, 0.1f, 3f, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Anim: x{_animSpeed:0.00}  in:{_animIn:0.0} out:{_animOut:0.0} t:{_animTime:0.0}", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			_animIn = FloatField("in", _animIn);
			_animOut = FloatField("out", _animOut);
			_animTime = FloatField("time", _animTime);
			GUILayout.EndHorizontal();
			if (GUILayout.Button("Apply Anim Speed", Array.Empty<GUILayoutOption>()))
			{
				OverrideAnim(_animSpeed, _animIn, _animOut, _animTime);
			}
		});
		GUILayout.Space(6f);
		GUILayout.Label("Insert → panel aç/kapat  |  pencere üstten sürüklenir", Array.Empty<GUILayoutOption>());
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
	}

	private void DrawSection(string title, Action body)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Space(6f);
		GUILayout.Label("<b>" + title + "</b>", new GUIStyle(GUI.skin.label)
		{
			richText = true
		}, Array.Empty<GUILayoutOption>());
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(1f, 1f, 1f, 0.06f);
		GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
		GUI.backgroundColor = backgroundColor;
		try
		{
			body?.Invoke();
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[REPO] UI section err: " + ex.Message));
		}
		GUILayout.EndVertical();
	}

	private static float FloatField(string label, float v)
	{
		GUILayout.Label(label + ":", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) });
		float result = v;
		float.TryParse(GUILayout.TextField(v.ToString("0.0"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }), out result);
		return result;
	}

	private void TryWarmupReflection()
	{
		Try(delegate
		{
			_tPlayerController = FindTypeLike("PlayerController");
			_tPlayerAvatar = FindTypeLike("PlayerAvatar");
			_tPlayerHealth = FindTypeLike("PlayerHealth");
			_tInventory = FindTypeLike("Inventory");
			_tEnemy = FindTypeLike("Enemy");
			if (_tPlayerController != null)
			{
				_fPC_instance = _tPlayerController.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				_pPC_EnergyCurrent = _tPlayerController.GetProperty("EnergyCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_pPC_EnergyStart = _tPlayerController.GetProperty("EnergyStart", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_mPC_OverrideTimeScale = _tPlayerController.GetMethod("OverrideTimeScale", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_tPlayerAvatar != null)
			{
				_pPA_isLocal = _tPlayerAvatar.GetProperty("isLocal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_pPA_photonView = _tPlayerAvatar.GetProperty("photonView", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (_pPA_photonView != null)
				{
					_pPV_IsMine = _pPA_photonView.PropertyType?.GetProperty("IsMine", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				_mPA_OverrideAnimationSpeed = _tPlayerAvatar.GetMethod("OverrideAnimationSpeed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_tPlayerHealth != null)
			{
				_mPH_Heal = _tPlayerHealth.GetMethod("Heal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(int),
					typeof(bool)
				}, null);
			}
			if (_tInventory != null)
			{
				_fInv_instance = _tInventory.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				_mInv_ForceUnequip = _tInventory.GetMethod("ForceUnequip", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_mInv_DropAll = _tInventory.GetMethod("InventoryDropAll", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(Vector3),
					typeof(int)
				}, null);
				_mInv_GetBattery = _tInventory.GetMethod("GetBatteryStateFromInventorySpot", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(int) }, null);
			}
			if (_tEnemy != null)
			{
				_mEnemy_Freeze = _tEnemy.GetMethod("Freeze", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(float) }, null);
			}
		});
	}

	private object GetPlayerController()
	{
		if (_fPC_instance == null)
		{
			return null;
		}
		return _fPC_instance.GetValue(null);
	}

	private Component GetLocalAvatar()
	{
		if (_tPlayerAvatar == null)
		{
			return null;
		}
		MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
		MonoBehaviour[] array2 = array;
		bool flag2 = default(bool);
		bool flag3 = default(bool);
		foreach (MonoBehaviour val in array2)
		{
			Type type = ((object)val).GetType();
			if (type != _tPlayerAvatar)
			{
				continue;
			}
			bool flag = false;
			if (_pPA_isLocal != null)
			{
				object value = _pPA_isLocal.GetValue(val);
				int num;
				if (value is bool)
				{
					flag2 = (bool)value;
					num = 1;
				}
				else
				{
					num = 0;
				}
				if (((uint)num & (flag2 ? 1u : 0u)) != 0)
				{
					flag = true;
				}
			}
			if (!flag && _pPA_photonView != null && _pPV_IsMine != null)
			{
				object value2 = _pPA_photonView.GetValue(val);
				if (value2 != null)
				{
					object value3 = _pPV_IsMine.GetValue(value2);
					int num2;
					if (value3 is bool)
					{
						flag3 = (bool)value3;
						num2 = 1;
					}
					else
					{
						num2 = 0;
					}
					if (((uint)num2 & (flag3 ? 1u : 0u)) != 0)
					{
						flag = true;
					}
				}
			}
			if (flag)
			{
				return (Component)(object)val;
			}
		}
		return null;
	}

	private void HealLocal(int amount)
	{
		Component localAvatar = GetLocalAvatar();
		if ((Object)(object)localAvatar == (Object)null || _tPlayerHealth == null || _mPH_Heal == null)
		{
			Warn("Heal API yok");
			return;
		}
		Component healthComp = localAvatar.GetComponent(_tPlayerHealth);
		if ((Object)(object)healthComp == (Object)null)
		{
			Warn("PlayerHealth bulunamadı");
			return;
		}
		Try(delegate
		{
			_mPH_Heal.Invoke(healthComp, new object[2] { amount, true });
		});
	}

	private void ForceUnequip()
	{
		object inv = GetInventory();
		if (inv == null || _mInv_ForceUnequip == null)
		{
			Warn("ForceUnequip yok");
			return;
		}
		Try(delegate
		{
			_mInv_ForceUnequip.Invoke(inv, null);
		});
	}

	private void DropAll()
	{
		//IL_0061: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		object inv = GetInventory();
		Component localAvatar = GetLocalAvatar();
		if (inv == null || (Object)(object)localAvatar == (Object)null || _mInv_DropAll == null)
		{
			Warn("DropAll API yok");
			return;
		}
		Transform transform = localAvatar.transform;
		Vector3 pos = transform.position + transform.forward * 1.2f;
		int viewId = -1;
		PropertyInfo propertyInfo = _tPlayerAvatar?.GetProperty("photonView", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		object obj = ((propertyInfo != null) ? propertyInfo.GetValue(localAvatar) : null);
		if (obj != null)
		{
			PropertyInfo property = obj.GetType().GetProperty("ViewID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.GetValue(obj) is int num)
			{
				viewId = num;
			}
		}
		Try(delegate
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			_mInv_DropAll.Invoke(inv, new object[2] { pos, viewId });
		});
	}

	private int GetBattery(int index)
	{
		object inventory = GetInventory();
		if (inventory == null || _mInv_GetBattery == null)
		{
			return -1;
		}
		try
		{
			return (_mInv_GetBattery.Invoke(inventory, new object[1] { index }) is int num) ? num : (-1);
		}
		catch
		{
			return -1;
		}
	}

	private object GetInventory()
	{
		if (_tInventory == null)
		{
			return null;
		}
		if (_fInv_instance != null)
		{
			return _fInv_instance.GetValue(null);
		}
		MonoBehaviour val = Object.FindObjectOfType<MonoBehaviour>();
		MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
		MonoBehaviour[] array2 = array;
		foreach (MonoBehaviour val2 in array2)
		{
			if (((object)val2).GetType() == _tInventory)
			{
				return val2;
			}
		}
		return null;
	}

	private void FreezeAll(float seconds)
	{
		if (_tEnemy == null || _mEnemy_Freeze == null)
		{
			Warn("Enemy.Freeze yok");
			return;
		}
		MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
		int num = 0;
		MonoBehaviour[] array2 = array;
		foreach (MonoBehaviour mb in array2)
		{
			if (((object)mb).GetType() == _tEnemy)
			{
				Try(delegate
				{
					_mEnemy_Freeze.Invoke(mb, new object[1] { seconds });
				});
				num++;
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"[REPO] FreezeAll → {num} enemy");
	}

	private void OverrideTimeScale(float mult, float dur)
	{
		object pc = GetPlayerController();
		if (pc == null || _mPC_OverrideTimeScale == null)
		{
			Warn("OverrideTimeScale yok");
			return;
		}
		Try(delegate
		{
			ParameterInfo[] parameters = _mPC_OverrideTimeScale.GetParameters();
			if (parameters.Length == 2)
			{
				_mPC_OverrideTimeScale.Invoke(pc, new object[2] { mult, dur });
			}
			else if (parameters.Length == 1)
			{
				_mPC_OverrideTimeScale.Invoke(pc, new object[1] { mult });
			}
			else
			{
				_mPC_OverrideTimeScale.Invoke(pc, null);
			}
		});
	}

	private void OverrideAnim(float speed, float @in, float @out, float time)
	{
		Component av = GetLocalAvatar();
		if ((Object)(object)av == (Object)null || _mPA_OverrideAnimationSpeed == null)
		{
			Warn("OverrideAnimationSpeed yok");
			return;
		}
		Try(delegate
		{
			ParameterInfo[] parameters = _mPA_OverrideAnimationSpeed.GetParameters();
			if (parameters.Length >= 4)
			{
				_mPA_OverrideAnimationSpeed.Invoke(av, new object[4] { speed, @in, @out, time });
			}
			else if (parameters.Length == 1)
			{
				_mPA_OverrideAnimationSpeed.Invoke(av, new object[1] { speed });
			}
			else
			{
				_mPA_OverrideAnimationSpeed.Invoke(av, null);
			}
		});
	}

	private static Type FindTypeLike(string name)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			try
			{
				Type type = assembly.GetType(name, throwOnError: false);
				if (type != null)
				{
					return type;
				}
				Type[] types = assembly.GetTypes();
				Type[] array = types;
				foreach (Type type2 in array)
				{
					if (type2.Name == name || type2.FullName.EndsWith("." + name))
					{
						return type2;
					}
				}
			}
			catch
			{
			}
		}
		return null;
	}

	private static float ReadFloat(object obj, PropertyInfo p)
	{
		try
		{
			if (obj != null && p != null)
			{
				object value = p.GetValue(obj);
				if (value is float)
				{
					float result = (float)value;
					if (true)
					{
						return result;
					}
				}
			}
		}
		catch
		{
		}
		return 0f;
	}

	private static void WriteFloat(object obj, PropertyInfo p, float v)
	{
		try
		{
			if (obj != null && p != null && p.CanWrite)
			{
				p.SetValue(obj, v);
			}
		}
		catch
		{
		}
	}

	private static void Try(Action a)
	{
		try
		{
			a();
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[REPO] " + ex.Message));
		}
	}

	private static void Warn(string m)
	{
		Debug.LogWarning((object)("[REPO] " + m));
	}
}

RepoInGameUI.dll

Decompiled 3 months ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
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("modmenu")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("modmenu")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("86389f4a-9dc7-47ba-9a50-a625db59448a")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace RepoMod.Reflected;

[BepInPlugin("mylf.repo.mod.ui.reflected", "REPO In-Game UI (Reflected)", "1.0.0")]
public class RepoModUIReflected : BaseUnityPlugin
{
	private Rect _win = new Rect(40f, 40f, 460f, 560f);

	private bool _show;

	private int _healAmount = 25;

	private float _freezeSec = 3f;

	private int _batteryIndex = 0;

	private float _timeScale = 0.8f;

	private float _timeScaleDur = 1.5f;

	private float _animSpeed = 1.5f;

	private float _animIn = 6f;

	private float _animOut = 4f;

	private float _animTime = 0.1f;

	private float _staminaUi = 50f;

	private Type _tPlayerController;

	private Type _tPlayerAvatar;

	private Type _tPlayerHealth;

	private Type _tInventory;

	private Type _tEnemy;

	private FieldInfo _fPC_instance;

	private PropertyInfo _pPC_EnergyCurrent;

	private PropertyInfo _pPC_EnergyStart;

	private MethodInfo _mPC_OverrideTimeScale;

	private PropertyInfo _pPA_isLocal;

	private PropertyInfo _pPA_photonView;

	private PropertyInfo _pPV_IsMine;

	private MethodInfo _mPA_OverrideAnimationSpeed;

	private MethodInfo _mPH_Heal;

	private FieldInfo _fInv_instance;

	private MethodInfo _mInv_ForceUnequip;

	private MethodInfo _mInv_DropAll;

	private MethodInfo _mInv_GetBattery;

	private MethodInfo _mEnemy_Freeze;

	private void Awake()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"[REPO][ReflectedUI] yüklendi — INSERT ile aç/kapa");
		TryWarmupReflection();
	}

	private void Update()
	{
		if (Input.GetKeyDown((KeyCode)277))
		{
			_show = !_show;
		}
	}

	private void OnGUI()
	{
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_0023: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Expected O, but got Unknown
		//IL_002d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		if (_show)
		{
			_win = GUI.Window(5356253, _win, new WindowFunction(DrawWindow), "REPO MOD PANEL (Reflected)");
		}
	}

	private void DrawWindow(int id)
	{
		//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.BeginVertical(Array.Empty<GUILayoutOption>());
		DrawSection("Player — Health/Stamina", delegate
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Heal Amount:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(95f) });
			int.TryParse(GUILayout.TextField(_healAmount.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }), out _healAmount);
			if (GUILayout.Button("+Heal", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				HealLocal(Mathf.Max(1, _healAmount));
			}
			if (GUILayout.Button("Full Heal", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(100f) }))
			{
				HealLocal(999999);
			}
			GUILayout.EndHorizontal();
			object playerController = GetPlayerController();
			float num = ReadFloat(playerController, _pPC_EnergyCurrent);
			float num2 = ReadFloat(playerController, _pPC_EnergyStart);
			if (num2 <= 0f)
			{
				num2 = Mathf.Max(100f, num);
			}
			_staminaUi = Mathf.Clamp((_staminaUi <= 0f) ? num : _staminaUi, 0f, Mathf.Max(1f, num2));
			GUILayout.Label($"Stamina (EnergyCurrent): {num:0.0} / {num2:0.0}", Array.Empty<GUILayoutOption>());
			float num3 = GUILayout.HorizontalSlider(_staminaUi, 0f, Mathf.Max(1f, num2), Array.Empty<GUILayoutOption>());
			if (Math.Abs(num3 - _staminaUi) > 0.0001f)
			{
				_staminaUi = num3;
				WriteFloat(playerController, _pPC_EnergyCurrent, _staminaUi);
			}
		});
		DrawSection("Inventory", delegate
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Force Unequip", Array.Empty<GUILayoutOption>()))
			{
				ForceUnequip();
			}
			if (GUILayout.Button("Drop All", Array.Empty<GUILayoutOption>()))
			{
				DropAll();
			}
			GUILayout.EndHorizontal();
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Battery slot:", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			int.TryParse(GUILayout.TextField(_batteryIndex.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(40f) }), out _batteryIndex);
			if (GUILayout.Button("Check", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(70f) }))
			{
				int battery = GetBattery(_batteryIndex);
				GUILayout.Label((battery >= 0) ? $"→ {battery}%" : "→ boş/yok", Array.Empty<GUILayoutOption>());
			}
			GUILayout.EndHorizontal();
		});
		DrawSection("Enemies", delegate
		{
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			GUILayout.Label("Freeze (sec):", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(90f) });
			float.TryParse(GUILayout.TextField(_freezeSec.ToString("0.0"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(60f) }), out _freezeSec);
			if (GUILayout.Button("Freeze All Visible", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(150f) }))
			{
				FreezeAll(Mathf.Max(0.1f, _freezeSec));
			}
			GUILayout.EndHorizontal();
		});
		DrawSection("Time & Animation", delegate
		{
			_timeScale = GUILayout.HorizontalSlider(_timeScale, 0.1f, 1.5f, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"TimeScale: x{_timeScale:0.00}  dur:{_timeScaleDur:0.0}s", Array.Empty<GUILayoutOption>());
			_timeScaleDur = GUILayout.HorizontalSlider(_timeScaleDur, 0.1f, 5f, Array.Empty<GUILayoutOption>());
			if (GUILayout.Button("Apply TimeScale", Array.Empty<GUILayoutOption>()))
			{
				OverrideTimeScale(_timeScale, _timeScaleDur);
			}
			GUILayout.Space(6f);
			_animSpeed = GUILayout.HorizontalSlider(_animSpeed, 0.1f, 3f, Array.Empty<GUILayoutOption>());
			GUILayout.Label($"Anim: x{_animSpeed:0.00}  in:{_animIn:0.0} out:{_animOut:0.0} t:{_animTime:0.0}", Array.Empty<GUILayoutOption>());
			GUILayout.BeginHorizontal(Array.Empty<GUILayoutOption>());
			_animIn = FloatField("in", _animIn);
			_animOut = FloatField("out", _animOut);
			_animTime = FloatField("time", _animTime);
			GUILayout.EndHorizontal();
			if (GUILayout.Button("Apply Anim Speed", Array.Empty<GUILayoutOption>()))
			{
				OverrideAnim(_animSpeed, _animIn, _animOut, _animTime);
			}
		});
		GUILayout.Space(6f);
		GUILayout.Label("Insert → panel aç/kapat  |  pencere üstten sürüklenir", Array.Empty<GUILayoutOption>());
		GUILayout.EndVertical();
		GUI.DragWindow(new Rect(0f, 0f, 10000f, 22f));
	}

	private void DrawSection(string title, Action body)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		//IL_003e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0043: Unknown result type (might be due to invalid IL or missing references)
		//IL_0058: Unknown result type (might be due to invalid IL or missing references)
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		GUILayout.Space(6f);
		GUILayout.Label("<b>" + title + "</b>", new GUIStyle(GUI.skin.label)
		{
			richText = true
		}, Array.Empty<GUILayoutOption>());
		Color backgroundColor = GUI.backgroundColor;
		GUI.backgroundColor = new Color(1f, 1f, 1f, 0.06f);
		GUILayout.BeginVertical(GUIStyle.op_Implicit("box"), Array.Empty<GUILayoutOption>());
		GUI.backgroundColor = backgroundColor;
		try
		{
			body?.Invoke();
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[REPO] UI section err: " + ex.Message));
		}
		GUILayout.EndVertical();
	}

	private static float FloatField(string label, float v)
	{
		GUILayout.Label(label + ":", (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(28f) });
		float result = v;
		float.TryParse(GUILayout.TextField(v.ToString("0.0"), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.Width(50f) }), out result);
		return result;
	}

	private void TryWarmupReflection()
	{
		Try(delegate
		{
			_tPlayerController = FindTypeLike("PlayerController");
			_tPlayerAvatar = FindTypeLike("PlayerAvatar");
			_tPlayerHealth = FindTypeLike("PlayerHealth");
			_tInventory = FindTypeLike("Inventory");
			_tEnemy = FindTypeLike("Enemy");
			if (_tPlayerController != null)
			{
				_fPC_instance = _tPlayerController.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				_pPC_EnergyCurrent = _tPlayerController.GetProperty("EnergyCurrent", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_pPC_EnergyStart = _tPlayerController.GetProperty("EnergyStart", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_mPC_OverrideTimeScale = _tPlayerController.GetMethod("OverrideTimeScale", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_tPlayerAvatar != null)
			{
				_pPA_isLocal = _tPlayerAvatar.GetProperty("isLocal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_pPA_photonView = _tPlayerAvatar.GetProperty("photonView", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (_pPA_photonView != null)
				{
					_pPV_IsMine = _pPA_photonView.PropertyType?.GetProperty("IsMine", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				}
				_mPA_OverrideAnimationSpeed = _tPlayerAvatar.GetMethod("OverrideAnimationSpeed", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			}
			if (_tPlayerHealth != null)
			{
				_mPH_Heal = _tPlayerHealth.GetMethod("Heal", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(int),
					typeof(bool)
				}, null);
			}
			if (_tInventory != null)
			{
				_fInv_instance = _tInventory.GetField("instance", BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic);
				_mInv_ForceUnequip = _tInventory.GetMethod("ForceUnequip", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				_mInv_DropAll = _tInventory.GetMethod("InventoryDropAll", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[2]
				{
					typeof(Vector3),
					typeof(int)
				}, null);
				_mInv_GetBattery = _tInventory.GetMethod("GetBatteryStateFromInventorySpot", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(int) }, null);
			}
			if (_tEnemy != null)
			{
				_mEnemy_Freeze = _tEnemy.GetMethod("Freeze", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic, null, new Type[1] { typeof(float) }, null);
			}
		});
	}

	private object GetPlayerController()
	{
		if (_fPC_instance == null)
		{
			return null;
		}
		return _fPC_instance.GetValue(null);
	}

	private Component GetLocalAvatar()
	{
		if (_tPlayerAvatar == null)
		{
			return null;
		}
		MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
		MonoBehaviour[] array2 = array;
		bool flag2 = default(bool);
		bool flag3 = default(bool);
		foreach (MonoBehaviour val in array2)
		{
			Type type = ((object)val).GetType();
			if (type != _tPlayerAvatar)
			{
				continue;
			}
			bool flag = false;
			if (_pPA_isLocal != null)
			{
				object value = _pPA_isLocal.GetValue(val);
				int num;
				if (value is bool)
				{
					flag2 = (bool)value;
					num = 1;
				}
				else
				{
					num = 0;
				}
				if (((uint)num & (flag2 ? 1u : 0u)) != 0)
				{
					flag = true;
				}
			}
			if (!flag && _pPA_photonView != null && _pPV_IsMine != null)
			{
				object value2 = _pPA_photonView.GetValue(val);
				if (value2 != null)
				{
					object value3 = _pPV_IsMine.GetValue(value2);
					int num2;
					if (value3 is bool)
					{
						flag3 = (bool)value3;
						num2 = 1;
					}
					else
					{
						num2 = 0;
					}
					if (((uint)num2 & (flag3 ? 1u : 0u)) != 0)
					{
						flag = true;
					}
				}
			}
			if (flag)
			{
				return (Component)(object)val;
			}
		}
		return null;
	}

	private void HealLocal(int amount)
	{
		Component localAvatar = GetLocalAvatar();
		if ((Object)(object)localAvatar == (Object)null || _tPlayerHealth == null || _mPH_Heal == null)
		{
			Warn("Heal API yok");
			return;
		}
		Component healthComp = localAvatar.GetComponent(_tPlayerHealth);
		if ((Object)(object)healthComp == (Object)null)
		{
			Warn("PlayerHealth bulunamadı");
			return;
		}
		Try(delegate
		{
			_mPH_Heal.Invoke(healthComp, new object[2] { amount, true });
		});
	}

	private void ForceUnequip()
	{
		object inv = GetInventory();
		if (inv == null || _mInv_ForceUnequip == null)
		{
			Warn("ForceUnequip yok");
			return;
		}
		Try(delegate
		{
			_mInv_ForceUnequip.Invoke(inv, null);
		});
	}

	private void DropAll()
	{
		//IL_0061: 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_0071: Unknown result type (might be due to invalid IL or missing references)
		//IL_0076: Unknown result type (might be due to invalid IL or missing references)
		//IL_007b: Unknown result type (might be due to invalid IL or missing references)
		object inv = GetInventory();
		Component localAvatar = GetLocalAvatar();
		if (inv == null || (Object)(object)localAvatar == (Object)null || _mInv_DropAll == null)
		{
			Warn("DropAll API yok");
			return;
		}
		Transform transform = localAvatar.transform;
		Vector3 pos = transform.position + transform.forward * 1.2f;
		int viewId = -1;
		PropertyInfo propertyInfo = _tPlayerAvatar?.GetProperty("photonView", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		object obj = ((propertyInfo != null) ? propertyInfo.GetValue(localAvatar) : null);
		if (obj != null)
		{
			PropertyInfo property = obj.GetType().GetProperty("ViewID", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			if (property != null && property.GetValue(obj) is int num)
			{
				viewId = num;
			}
		}
		Try(delegate
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			_mInv_DropAll.Invoke(inv, new object[2] { pos, viewId });
		});
	}

	private int GetBattery(int index)
	{
		object inventory = GetInventory();
		if (inventory == null || _mInv_GetBattery == null)
		{
			return -1;
		}
		try
		{
			return (_mInv_GetBattery.Invoke(inventory, new object[1] { index }) is int num) ? num : (-1);
		}
		catch
		{
			return -1;
		}
	}

	private object GetInventory()
	{
		if (_tInventory == null)
		{
			return null;
		}
		if (_fInv_instance != null)
		{
			return _fInv_instance.GetValue(null);
		}
		MonoBehaviour val = Object.FindObjectOfType<MonoBehaviour>();
		MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
		MonoBehaviour[] array2 = array;
		foreach (MonoBehaviour val2 in array2)
		{
			if (((object)val2).GetType() == _tInventory)
			{
				return val2;
			}
		}
		return null;
	}

	private void FreezeAll(float seconds)
	{
		if (_tEnemy == null || _mEnemy_Freeze == null)
		{
			Warn("Enemy.Freeze yok");
			return;
		}
		MonoBehaviour[] array = Object.FindObjectsOfType<MonoBehaviour>();
		int num = 0;
		MonoBehaviour[] array2 = array;
		foreach (MonoBehaviour mb in array2)
		{
			if (((object)mb).GetType() == _tEnemy)
			{
				Try(delegate
				{
					_mEnemy_Freeze.Invoke(mb, new object[1] { seconds });
				});
				num++;
			}
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)$"[REPO] FreezeAll → {num} enemy");
	}

	private void OverrideTimeScale(float mult, float dur)
	{
		object pc = GetPlayerController();
		if (pc == null || _mPC_OverrideTimeScale == null)
		{
			Warn("OverrideTimeScale yok");
			return;
		}
		Try(delegate
		{
			ParameterInfo[] parameters = _mPC_OverrideTimeScale.GetParameters();
			if (parameters.Length == 2)
			{
				_mPC_OverrideTimeScale.Invoke(pc, new object[2] { mult, dur });
			}
			else if (parameters.Length == 1)
			{
				_mPC_OverrideTimeScale.Invoke(pc, new object[1] { mult });
			}
			else
			{
				_mPC_OverrideTimeScale.Invoke(pc, null);
			}
		});
	}

	private void OverrideAnim(float speed, float @in, float @out, float time)
	{
		Component av = GetLocalAvatar();
		if ((Object)(object)av == (Object)null || _mPA_OverrideAnimationSpeed == null)
		{
			Warn("OverrideAnimationSpeed yok");
			return;
		}
		Try(delegate
		{
			ParameterInfo[] parameters = _mPA_OverrideAnimationSpeed.GetParameters();
			if (parameters.Length >= 4)
			{
				_mPA_OverrideAnimationSpeed.Invoke(av, new object[4] { speed, @in, @out, time });
			}
			else if (parameters.Length == 1)
			{
				_mPA_OverrideAnimationSpeed.Invoke(av, new object[1] { speed });
			}
			else
			{
				_mPA_OverrideAnimationSpeed.Invoke(av, null);
			}
		});
	}

	private static Type FindTypeLike(string name)
	{
		Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
		foreach (Assembly assembly in assemblies)
		{
			try
			{
				Type type = assembly.GetType(name, throwOnError: false);
				if (type != null)
				{
					return type;
				}
				Type[] types = assembly.GetTypes();
				Type[] array = types;
				foreach (Type type2 in array)
				{
					if (type2.Name == name || type2.FullName.EndsWith("." + name))
					{
						return type2;
					}
				}
			}
			catch
			{
			}
		}
		return null;
	}

	private static float ReadFloat(object obj, PropertyInfo p)
	{
		try
		{
			if (obj != null && p != null)
			{
				object value = p.GetValue(obj);
				if (value is float)
				{
					float result = (float)value;
					if (true)
					{
						return result;
					}
				}
			}
		}
		catch
		{
		}
		return 0f;
	}

	private static void WriteFloat(object obj, PropertyInfo p, float v)
	{
		try
		{
			if (obj != null && p != null && p.CanWrite)
			{
				p.SetValue(obj, v);
			}
		}
		catch
		{
		}
	}

	private static void Try(Action a)
	{
		try
		{
			a();
		}
		catch (Exception ex)
		{
			Debug.LogWarning((object)("[REPO] " + ex.Message));
		}
	}

	private static void Warn(string m)
	{
		Debug.LogWarning((object)("[REPO] " + m));
	}
}