Decompiled source of ChatResizer v1.2.2

ChatResizer.dll

Decompiled 2 months ago
using System;
using System.Diagnostics;
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 UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("GeneralMod")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GeneralMod")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("96629134-eb8c-4fef-b686-c7f1ca5c70c6")]
[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("com.reckss.erenshor.chatparanchorscaler", "ChatPar Anchor Scaler", "1.2.2")]
public class ChatParAnchorScalerMod : BaseUnityPlugin
{
	private class AnchorScaler : MonoBehaviour
	{
		private Transform _root;

		private RectTransform _anchor;

		private Vector3 _targetScale;

		private bool _scaling;

		private Vector3 _startScale;

		private Vector2 _startMouse;

		private const float Sensitivity = 0.005f;

		private const float MinScale = 0.1f;

		private const float SmoothSpeed = 10f;

		public AnchorScaler Init(Transform root, RectTransform anchor)
		{
			//IL_0025: Unknown result type (might be due to invalid IL or missing references)
			//IL_002f: 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)
			//IL_0040: Unknown result type (might be due to invalid IL or missing references)
			_root = root;
			_anchor = anchor;
			_targetScale = new Vector3(chatScaleX.Value, chatScaleY.Value, root.localScale.z);
			_root.localScale = _targetScale;
			return this;
		}

		private void Update()
		{
			//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_000b: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00de: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e3: Unknown result type (might be due to invalid IL or missing references)
			//IL_0084: Unknown result type (might be due to invalid IL or missing references)
			//IL_0144: Unknown result type (might be due to invalid IL or missing references)
			//IL_0169: Unknown result type (might be due to invalid IL or missing references)
			//IL_0193: Unknown result type (might be due to invalid IL or missing references)
			//IL_0198: Unknown result type (might be due to invalid IL or missing references)
			//IL_0101: Unknown result type (might be due to invalid IL or missing references)
			//IL_012b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_020b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0211: Unknown result type (might be due to invalid IL or missing references)
			//IL_0221: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			Vector2 val = Vector2.op_Implicit(Input.mousePosition);
			bool flag = Input.GetKey((KeyCode)304) || Input.GetKey((KeyCode)303);
			bool flag2 = Input.GetMouseButtonDown(2) || (flag && Input.GetMouseButtonDown(0));
			bool flag3 = Input.GetMouseButton(2) || (flag && Input.GetMouseButton(0));
			bool flag4 = Input.GetMouseButtonUp(2) || (Input.GetMouseButtonUp(0) && flag);
			if (!_scaling)
			{
				if (flag2 && RectTransformUtility.RectangleContainsScreenPoint(_anchor, val, (Camera)null))
				{
					_scaling = true;
					_startScale = _root.localScale;
					_startMouse = val;
					log.LogInfo((object)"[ChatParAnchorScaler] Scaling started");
				}
			}
			else if (flag3)
			{
				Vector2 val2 = val - _startMouse;
				if (lockAspect.Value)
				{
					float num = Mathf.Max(_startScale.x + val2.x * 0.005f, 0.1f);
					_targetScale = new Vector3(num, num, _startScale.z);
				}
				else
				{
					float num2 = Mathf.Max(_startScale.x + val2.x * 0.005f, 0.1f);
					float num3 = Mathf.Max(_startScale.y - val2.y * 0.005f, 0.1f);
					_targetScale = new Vector3(num2, num3, _startScale.z);
				}
			}
			else if (flag4)
			{
				_scaling = false;
				chatScaleX.Value = _targetScale.x;
				chatScaleY.Value = _targetScale.y;
				((BaseUnityPlugin)instance).Config.Save();
				log.LogInfo((object)"[ChatParAnchorScaler] Scaling ended, saved values");
			}
			_root.localScale = Vector3.Lerp(_root.localScale, _targetScale, 10f * Time.deltaTime);
		}
	}

	private static ManualLogSource log;

	private static ChatParAnchorScalerMod instance;

	private static ConfigEntry<bool> lockAspect;

	private static ConfigEntry<float> chatScaleX;

	private static ConfigEntry<float> chatScaleY;

	private void Awake()
	{
		//IL_008f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Expected O, but got Unknown
		//IL_00bd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ca: Expected O, but got Unknown
		instance = this;
		log = ((BaseUnityPlugin)this).Logger;
		lockAspect = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "LockAspectRatio", true, "When true, scales X and Y together; when false, allows independent X/Y scaling.");
		chatScaleX = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ChatScaleX", 1f, "Saved X scale for ChatPar");
		chatScaleY = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ChatScaleY", 1f, "Saved Y scale for ChatPar");
		log.LogInfo((object)"[ChatParAnchorScaler] Patching IDLog.Start()");
		Harmony val = new Harmony("com.reckss.erenshor.chatparanchorscaler");
		val.Patch((MethodBase)AccessTools.Method(typeof(IDLog), "Start", (Type[])null, (Type[])null), (HarmonyMethod)null, new HarmonyMethod(typeof(ChatParAnchorScalerMod), "OnIDLogStart", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
	}

	private static void OnIDLogStart(IDLog __instance)
	{
		GameObject val = GameObject.Find("UI/UIElements/LogCanvas/ChatPar");
		if ((Object)(object)val == (Object)null)
		{
			log.LogWarning((object)"[ChatParAnchorScaler] ChatPar not found!");
			return;
		}
		Transform obj = val.transform.Find("DragChat");
		RectTransform val2 = (RectTransform)(object)((obj is RectTransform) ? obj : null);
		if ((Object)(object)val2 == (Object)null)
		{
			log.LogWarning((object)"[ChatParAnchorScaler] DragChat handle not found; disabling scaler.");
			return;
		}
		val.AddComponent<AnchorScaler>().Init(val.transform, val2);
		log.LogInfo((object)"[ChatParAnchorScaler] Scaler attached to DragChat");
	}
}