Decompiled source of QuotaReward v1.0.0

QuotaReward.dll

Decompiled 4 hours ago
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("QuotaReward")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("QuotaReward")]
[assembly: AssemblyCopyright("Copyright ©  2025")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("67e3800e-2ee1-4fef-99f9-10ee153408ff")]
[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("finishim.quotareward", "QuotaReward", "1.0.0")]
public class QuotaReward : BaseUnityPlugin
{
	public static QuotaReward Instance;

	internal static ConfigEntry<int> ShieldPerQuota;

	internal static ConfigEntry<int> ShieldMaxLimit;

	internal static ConfigEntry<string> ShieldLabel;

	internal static int ShieldMax = 0;

	internal static int ShieldCurrent = 0;

	private static int lastTimesFulfilledQuota = -1;

	private static string SavePath
	{
		get
		{
			if ((Object)(object)GameNetworkManager.Instance == (Object)null)
			{
				return null;
			}
			string currentSaveFileName = GameNetworkManager.Instance.currentSaveFileName;
			return Path.Combine(Application.persistentDataPath, "QuotaReward_Shield_" + currentSaveFileName + ".txt");
		}
	}

	private void Awake()
	{
		//IL_0074: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		ShieldPerQuota = ((BaseUnityPlugin)this).Config.Bind<int>("Shield", "ShieldPerQuota", 25, "Amount of shield gained each time a quota is successfully completed.");
		ShieldMaxLimit = ((BaseUnityPlugin)this).Config.Bind<int>("Shield", "ShieldMaxLimit", 500, "Maximum shield capacity a player can reach across the run.");
		ShieldLabel = ((BaseUnityPlugin)this).Config.Bind<string>("HUD", "ShieldLabel", "Shield", "Label shown on the HUD for the shield display (visual only).");
		new Harmony("finishim.quotareward").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"QuotaReward loaded and actived.");
		((BaseUnityPlugin)this).Logger.LogInfo((object)"FUNCIONO CTM!!! VIVA CHILE MIERDA!!!");
	}

	private void Update()
	{
		if (Object.op_Implicit((Object)(object)GameNetworkManager.Instance) && GameNetworkManager.Instance.isHostingGame && !((Object)(object)TimeOfDay.Instance == (Object)null))
		{
			CheckQuotaProgress();
		}
	}

	private void CheckQuotaProgress()
	{
		int timesFulfilledQuota = TimeOfDay.Instance.timesFulfilledQuota;
		if (lastTimesFulfilledQuota == -1)
		{
			lastTimesFulfilledQuota = timesFulfilledQuota;
			return;
		}
		if (timesFulfilledQuota > lastTimesFulfilledQuota)
		{
			lastTimesFulfilledQuota = timesFulfilledQuota;
			ApplyQuotaReward();
		}
		if (timesFulfilledQuota == 0 && lastTimesFulfilledQuota > 0)
		{
			lastTimesFulfilledQuota = 0;
			ResetAllShield();
		}
	}

	internal static void SyncQuotaState()
	{
		if (!((Object)(object)TimeOfDay.Instance == (Object)null))
		{
			lastTimesFulfilledQuota = TimeOfDay.Instance.timesFulfilledQuota;
		}
	}

	internal static void SaveShield()
	{
		try
		{
			File.WriteAllText(SavePath, $"{ShieldMax}|{ShieldCurrent}");
		}
		catch
		{
		}
	}

	internal static void LoadShield()
	{
		if (!File.Exists(SavePath))
		{
			ShieldMax = 0;
			ShieldCurrent = 0;
			return;
		}
		try
		{
			string[] array = File.ReadAllText(SavePath).Split(new char[1] { '|' });
			ShieldMax = int.Parse(array[0]);
			ShieldCurrent = int.Parse(array[1]);
		}
		catch
		{
			ShieldMax = 0;
			ShieldCurrent = 0;
		}
	}

	internal static void ResetAllShield()
	{
		ShieldMax = 0;
		ShieldCurrent = 0;
		SaveShield();
		((BaseUnityPlugin)Instance).Logger.LogInfo((object)"[QuotaReward] Shield reset due to dismissal.");
	}

	internal static void ApplyQuotaReward()
	{
		ShieldMax += ShieldPerQuota.Value;
		ShieldMax = Mathf.Clamp(ShieldMax, 0, ShieldMaxLimit.Value);
		ShieldCurrent = ShieldMax;
		SaveShield();
		((BaseUnityPlugin)Instance).Logger.LogInfo((object)$"[QuotaReward] Quota completed! Shield increased by {ShieldPerQuota.Value}. Current Shield: {ShieldCurrent}/{ShieldMax}");
	}

	private void OnGUI()
	{
		//IL_003f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0045: Expected O, but got Unknown
		//IL_0062: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		if (Object.op_Implicit((Object)(object)StartOfRound.Instance) && ShieldMax > 0)
		{
			string text = ShieldLabel.Value;
			if (text.Length > 10)
			{
				text = text.Substring(0, 10);
			}
			GUIStyle val = new GUIStyle(GUI.skin.label);
			val.fontSize = 18;
			val.normal.textColor = new Color(0.4f, 0.8f, 1f);
			string text2 = $"{text}: {ShieldCurrent}/{ShieldMax}";
			float num = (float)Screen.width * 0.03f;
			float num2 = (float)Screen.height * 0.21f;
			GUI.Label(new Rect(num, num2, 260f, 30f), text2, val);
		}
	}
}
[HarmonyPatch(typeof(PlayerControllerB), "DamagePlayer")]
internal class ShieldDamagePatch
{
	private static bool Prefix(ref int damageNumber, PlayerControllerB __instance)
	{
		if ((Object)(object)__instance == (Object)null || __instance.isPlayerDead)
		{
			return true;
		}
		if (damageNumber <= 0)
		{
			return true;
		}
		if (damageNumber >= 999)
		{
			return true;
		}
		if (QuotaReward.ShieldCurrent > 0)
		{
			int num = Mathf.Min(QuotaReward.ShieldCurrent, damageNumber);
			QuotaReward.ShieldCurrent -= num;
			if (QuotaReward.ShieldCurrent < 0)
			{
				QuotaReward.ShieldCurrent = 0;
			}
			damageNumber -= num;
			if (damageNumber <= 0)
			{
				return false;
			}
		}
		return true;
	}
}
[HarmonyPatch(typeof(StartOfRound), "Start")]
internal class LoadShieldPatch
{
	private static void Postfix()
	{
		QuotaReward.LoadShield();
		QuotaReward.SyncQuotaState();
	}
}
[HarmonyPatch(typeof(TimeOfDay), "OnDayChanged")]
internal class RestoreShieldOnNewDayPatch
{
	private static void Postfix()
	{
		if (QuotaReward.ShieldMax > 0)
		{
			QuotaReward.ShieldCurrent = QuotaReward.ShieldMax;
			QuotaReward.SaveShield();
		}
	}
}