Decompiled source of EasyRepairArea v0.1.1

EasyRepairArea.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("EasyRepairArea")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.1.0")]
[assembly: AssemblyInformationalVersion("0.1.1")]
[assembly: AssemblyProduct("EasyRepairArea")]
[assembly: AssemblyTitle("EasyRepairArea")]
[assembly: AssemblyVersion("0.1.1.0")]
namespace EasyRepairArea;

[BepInPlugin("fernasz.easyrepairarea", "EasyRepairArea", "0.1.1")]
public class EasyRepairArea : BaseUnityPlugin
{
	public const string PluginGuid = "fernasz.easyrepairarea";

	public const string PluginName = "EasyRepairArea";

	public const string PluginVersion = "0.1.1";

	private static ManualLogSource Log;

	private ConfigEntry<string> cfgKey;

	private ConfigEntry<float> cfgRadius;

	private ConfigEntry<bool> cfgEnabled;

	private KeyCode _key = (KeyCode)270;

	private float _cooldown;

	private void Awake()
	{
		//IL_0096: Unknown result type (might be due to invalid IL or missing references)
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		cfgEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Geral", "Ativado", true, "Liga/desliga o mod");
		cfgRadius = ((BaseUnityPlugin)this).Config.Bind<float>("Geral", "Raio", 100f, "Raio de reparo em metros");
		cfgKey = ((BaseUnityPlugin)this).Config.Bind<string>("Geral", "Tecla", "KeypadPlus", "Tecla do atalho (nome de KeyCode da Unity). Exemplos: KeypadPlus, KeypadEnter, F8, BackQuote");
		KeyCode result;
		bool flag = Enum.TryParse<KeyCode>(cfgKey.Value, ignoreCase: true, out result);
		_key = (KeyCode)((!flag) ? 270 : ((int)result));
		if (!flag)
		{
			Log.LogWarning((object)("Tecla '" + cfgKey.Value + "' inválida, usando KeypadPlus."));
		}
		Log.LogInfo((object)string.Format("{0} v{1} carregado. Tecla: {2}, raio: {3}m", "EasyRepairArea", "0.1.1", _key, cfgRadius.Value));
	}

	private void Update()
	{
		//IL_003c: Unknown result type (might be due to invalid IL or missing references)
		if (cfgEnabled.Value)
		{
			if (_cooldown > 0f)
			{
				_cooldown -= Time.unscaledDeltaTime;
			}
			else if (Input.GetKeyDown(_key) && !((Object)(object)Player.m_localPlayer == (Object)null) && !Game.IsPaused())
			{
				_cooldown = 0.5f;
				RepairArea(cfgRadius.Value);
			}
		}
	}

	private void RepairArea(float radius)
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Unknown result type (might be due to invalid IL or missing references)
		//IL_004a: Unknown result type (might be due to invalid IL or missing references)
		Player localPlayer = Player.m_localPlayer;
		Vector3 position = ((Component)localPlayer).transform.position;
		int num = 0;
		WearNTear[] array = Object.FindObjectsOfType<WearNTear>();
		foreach (WearNTear val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				Vector3 val2 = ((Component)val).transform.position - position;
				if (!(((Vector3)(ref val2)).sqrMagnitude > radius * radius))
				{
					val.Repair();
					num++;
				}
			}
		}
		if (num > 0)
		{
			((Character)localPlayer).Message((MessageType)1, $"Reparadas {num} construções num raio de {radius:0}m", 0, (Sprite)null, false);
			Log.LogInfo((object)$"Reparo em área: {num} peças num raio de {radius}m");
		}
	}
}