Decompiled source of RoguelikeQoL v0.1.0

plugins/RoguelikeQoL/RoguelikeQoL.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using Burst2Flame;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = "")]
[assembly: AssemblyCompany("RoguelikeQoL")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Qualidade de vida para o Stolen Realm (HUD de modificadores da run).")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0")]
[assembly: AssemblyProduct("RoguelikeQoL")]
[assembly: AssemblyTitle("RoguelikeQoL")]
[assembly: AssemblyVersion("0.1.0.0")]
namespace RoguelikeQoL;

[BepInPlugin("com.gumatos.roguelikeqol", "Roguelike QoL", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
	internal static ManualLogSource Log { get; private set; }

	internal static ConfigEntry<bool> AtivarHud { get; private set; }

	private void Awake()
	{
		//IL_005d: Unknown result type (might be due to invalid IL or missing references)
		Log = ((BaseUnityPlugin)this).Logger;
		AtivarHud = ((BaseUnityPlugin)this).Config.Bind<bool>("Geral", "AtivarHUD", false, "Mostra o HUD de modificadores da run no canto superior esquerdo (Treasure Find / Gold Find / Exp Mod). Padrão: false (desligado).");
		if (!AtivarHud.Value)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Roguelike QoL carregado — HUD DESABILITADO (AtivarHUD=false no config).");
			return;
		}
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Roguelike QoL carregado — HUD habilitado.");
		new Harmony("com.gumatos.roguelikeqol").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"QoL: patch de gatilho (OptionsManager.Localize) aplicado; updater será criado na primeira UI.");
	}
}
[HarmonyPatch(typeof(OptionsManager), "Localize")]
public static class LocalizeHudTrigger
{
	private static void Postfix()
	{
		try
		{
			QoLUpdater.Ensure();
		}
		catch
		{
		}
	}
}
public class QoLUpdater : MonoBehaviour
{
	private const float RefreshInterval = 0.5f;

	private Text _hudText;

	private float _lastUpdate = -99f;

	private bool _loggedFirstTick;

	private bool _loggedFirstLocalize;

	private bool _loggedFirstText;

	private static bool _everDestroyed;

	public static QoLUpdater Instance { get; private set; }

	public static void Create()
	{
		//IL_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Expected O, but got Unknown
		if (!((Object)(object)Instance != (Object)null))
		{
			GameObject val = new GameObject("RoguelikeQoL_Updater");
			Object.DontDestroyOnLoad((Object)val);
			val.AddComponent<QoLUpdater>();
		}
	}

	public static void Ensure()
	{
		if ((Object)(object)Instance == (Object)null)
		{
			if (_everDestroyed)
			{
				Plugin.Log.LogWarning((object)"QoL: updater ausente — recriando (a Unity destruiu o anterior).");
			}
			Create();
		}
		if (!((Object)(object)Instance == (Object)null))
		{
			Instance.MarkLocalizeSeen();
			Instance.RefreshIfDue();
		}
	}

	private void Awake()
	{
		Instance = this;
		Plugin.Log.LogInfo((object)"QoL: updater criado.");
		CreateHud();
	}

	private void Start()
	{
		Plugin.Log.LogInfo((object)"QoL: Start() do updater chamado (objeto vivo na cena).");
	}

	private void OnDestroy()
	{
		Plugin.Log.LogWarning((object)"QoL: updater DESTRUÍDO pela Unity.");
		_everDestroyed = true;
		if ((Object)(object)Instance == (Object)(object)this)
		{
			Instance = null;
		}
	}

	internal void MarkLocalizeSeen()
	{
		if (!_loggedFirstLocalize)
		{
			_loggedFirstLocalize = true;
			Plugin.Log.LogInfo((object)"QoL: primeiro Localize recebido (a UI do jogo está rodando).");
		}
	}

	internal void RefreshIfDue()
	{
		if (!(Time.realtimeSinceStartup - _lastUpdate < 0.5f))
		{
			_lastUpdate = Time.realtimeSinceStartup;
			Refresh();
		}
	}

	private void Update()
	{
		if (!_loggedFirstTick)
		{
			_loggedFirstTick = true;
			Plugin.Log.LogInfo((object)"QoL: primeiro Update do updater OK (ciclo de vida funcionando).");
		}
		RefreshIfDue();
	}

	private void Refresh()
	{
		if ((Object)(object)_hudText == (Object)null)
		{
			return;
		}
		try
		{
			string text = BuildHudText();
			if (!_loggedFirstText && !string.IsNullOrEmpty(text))
			{
				_loggedFirstText = true;
				Plugin.Log.LogInfo((object)("QoL HUD texto: " + text.Replace("\n", " | ")));
			}
			_hudText.text = text;
		}
		catch (Exception ex)
		{
			Plugin.Log.LogWarning((object)("QoL HUD erro: " + ex.Message));
			_hudText.text = "";
		}
	}

	private void CreateHud()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000b: 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)
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bf: 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_00f2: Unknown result type (might be due to invalid IL or missing references)
		//IL_0106: Unknown result type (might be due to invalid IL or missing references)
		//IL_0120: Unknown result type (might be due to invalid IL or missing references)
		//IL_0135: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Unknown result type (might be due to invalid IL or missing references)
		//IL_015e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject("RoguelikeQoL_HUD");
		Object.DontDestroyOnLoad((Object)(object)val);
		Canvas obj = val.AddComponent<Canvas>();
		obj.renderMode = (RenderMode)0;
		obj.sortingOrder = 999;
		GameObject val2 = new GameObject("Panel");
		val2.transform.SetParent(val.transform, false);
		Text val3 = val2.AddComponent<Text>();
		Font val4 = Resources.GetBuiltinResource<Font>("LegacyRuntime.ttf");
		if ((Object)(object)val4 == (Object)null)
		{
			val4 = Font.CreateDynamicFontFromOSFont("Arial", 18);
		}
		val3.font = val4;
		Plugin.Log.LogInfo((object)("Roguelike QoL: HUD criado (fonte=" + (((Object)(object)val4 != (Object)null) ? ((Object)val4).name : "null") + ")."));
		val3.fontSize = 18;
		((Graphic)val3).color = new Color(1f, 0.95f, 0.6f, 0.95f);
		val3.horizontalOverflow = (HorizontalWrapMode)1;
		val3.verticalOverflow = (VerticalWrapMode)1;
		Outline obj2 = val2.AddComponent<Outline>();
		((Shadow)obj2).effectColor = new Color(0f, 0f, 0f, 0.9f);
		((Shadow)obj2).effectDistance = new Vector2(1.2f, -1.2f);
		RectTransform component = val2.GetComponent<RectTransform>();
		component.anchorMin = new Vector2(0f, 1f);
		component.anchorMax = new Vector2(0f, 1f);
		component.pivot = new Vector2(0f, 1f);
		component.anchoredPosition = new Vector2(12f, -12f);
		_hudText = val3;
		_hudText.text = "";
	}

	private static string BuildHudText()
	{
		NetworkingManager instance = NetworkingManager.Instance;
		if ((Object)(object)instance == (Object)null || instance.MyPartyCharacters == null || instance.MyPartyCharacters.Count == 0)
		{
			return "";
		}
		float num = 0f;
		float num2 = 0f;
		foreach (Character myPartyCharacter in instance.MyPartyCharacters)
		{
			if (myPartyCharacter != null)
			{
				num += myPartyCharacter["DropQuantityMod"];
				num2 += myPartyCharacter["GoldMod"];
			}
		}
		List<string> list = new List<string>();
		if (num > 0f)
		{
			list.Add($"Treasure Find: +{num:0.#}%");
		}
		if (num2 > 0f)
		{
			list.Add($"Gold Find: +{num2:0.#}%");
		}
		GameLogic instance2 = GameLogic.instance;
		BattleInfo val = ((instance2 != null) ? instance2.CurrentBattle : null);
		if ((Object)(object)val != (Object)null && !string.IsNullOrEmpty(val.expModifier) && float.TryParse(val.expModifier, out var result) && result > 0f)
		{
			list.Add($"Exp Mod: +{result:0.#}%");
		}
		return string.Join("\n", list);
	}
}