Decompiled source of RiseTogether v1.0.1

RiseTogether.dll

Decompiled a day ago
using System;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace SoloLeveling;

[BepInPlugin("yuri.RiseTogether", "Rise Together", "1.0.0")]
public class Plugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(Skills), "RaiseSkill")]
	private static class AoSubir
	{
		private static void Prefix(Skills __instance, ref float factor)
		{
			Aplicar = false;
			if (!Espalhando && !((Object)(object)Inst == (Object)null) && Inst.Ativo() && EhMeu(__instance))
			{
				__instance.m_useSkillCap = false;
				factor *= Inst.Multiplicador();
				Quanto = factor;
				Aplicar = true;
			}
		}

		private static void Postfix(Skills __instance, SkillType skillType)
		{
			//IL_0048: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_004e: Unknown result type (might be due to invalid IL or missing references)
			//IL_004f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0052: Unknown result type (might be due to invalid IL or missing references)
			//IL_0055: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Invalid comparison between Unknown and I4
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			if (!Aplicar || Espalhando)
			{
				return;
			}
			Aplicar = false;
			Espalhando = true;
			try
			{
				Array values = Enum.GetValues(typeof(SkillType));
				for (int i = 0; i < values.Length; i++)
				{
					SkillType val = (SkillType)values.GetValue(i);
					if (val != skillType && (int)val != 0 && (int)val != 999)
					{
						Skill val2 = Pegar(__instance, val);
						if (val2 != null && val2.m_info != null)
						{
							val2.Raise(Quanto);
						}
					}
				}
			}
			finally
			{
				Espalhando = false;
			}
		}
	}

	[HarmonyPatch(typeof(Skill), "Raise")]
	private static class SemTeto
	{
		private static bool Prefix(Skill __instance, float factor, ref bool __result)
		{
			if ((Object)(object)Inst == (Object)null || !Inst.Ativo() || __instance == null || __instance.m_info == null)
			{
				return true;
			}
			float num = __instance.m_info.m_increseStep * factor * Game.m_skillGainRate;
			__instance.m_accumulator += num;
			float num2 = Proxima(__instance.m_level);
			if (__instance.m_accumulator < num2)
			{
				__result = false;
				return false;
			}
			__instance.m_level += 1f;
			if (__instance.m_level < 0f)
			{
				__instance.m_level = 0f;
			}
			__instance.m_accumulator = 0f;
			__result = true;
			return false;
		}

		private static float Proxima(float nivel)
		{
			float num = Mathf.Floor(nivel + 1f);
			return Mathf.Pow(num, 1.5f) * 0.5f + 0.5f;
		}
	}

	[HarmonyPatch(typeof(Skills), "GetSkillFactor")]
	private static class SemTrava
	{
		private static bool Prefix(Skills __instance, SkillType skillType, ref float __result)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_0044: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)Inst == (Object)null || !Inst.Ativo() || !EhMeu(__instance))
			{
				return true;
			}
			if ((int)skillType == 0)
			{
				__result = 0f;
				return false;
			}
			float skillLevel = __instance.GetSkillLevel(skillType);
			__result = skillLevel / 100f;
			if (__result < 0f)
			{
				__result = 0f;
			}
			return false;
		}
	}

	public static Plugin Inst;

	public static bool Espalhando;

	public static bool Aplicar;

	public static float Quanto;

	private ConfigEntry<bool> Ligado;

	private ConfigEntry<int> Vezes;

	private bool guardouCap;

	private bool capOriginal;

	private static MethodInfo pegarSkill;

	private void Awake()
	{
		//IL_004e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0054: Expected O, but got Unknown
		Inst = this;
		Ligado = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Every action raises every skill at once, with multiplied experience. No level cap. Only your own game needs this mod.");
		Vezes = ((BaseUnityPlugin)this).Config.Bind<int>("General", "Times", 2, "How many times the experience comes in. The default is 2.");
		Harmony val = new Harmony("yuri.RiseTogether");
		val.PatchAll(typeof(Plugin).Assembly);
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Rise Together 1.0.0");
	}

	private void Update()
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null)
		{
			return;
		}
		Skills skills = ((Character)localPlayer).GetSkills();
		if (!((Object)(object)skills == (Object)null))
		{
			if (!guardouCap)
			{
				capOriginal = skills.m_useSkillCap;
				guardouCap = true;
			}
			if (Ligado.Value)
			{
				skills.m_useSkillCap = false;
			}
			else
			{
				skills.m_useSkillCap = capOriginal;
			}
		}
	}

	public bool Ativo()
	{
		return Ligado.Value;
	}

	public float Multiplicador()
	{
		int num = Vezes.Value;
		if (num < 1)
		{
			num = 1;
		}
		if (num > 5)
		{
			num = 5;
		}
		return num;
	}

	public static bool EhMeu(Skills habilidades)
	{
		Player localPlayer = Player.m_localPlayer;
		if ((Object)(object)localPlayer == (Object)null || (Object)(object)habilidades == (Object)null)
		{
			return false;
		}
		return (Object)(object)((Character)localPlayer).GetSkills() == (Object)(object)habilidades;
	}

	private static Skill Pegar(Skills habilidades, SkillType tipo)
	{
		//IL_0053: Unknown result type (might be due to invalid IL or missing references)
		//IL_0060: Unknown result type (might be due to invalid IL or missing references)
		//IL_0066: Expected O, but got Unknown
		if (pegarSkill == null)
		{
			pegarSkill = typeof(Skills).GetMethod("GetSkill", BindingFlags.Instance | BindingFlags.NonPublic);
		}
		if (pegarSkill == null)
		{
			return null;
		}
		return (Skill)pegarSkill.Invoke(habilidades, new object[1] { tipo });
	}
}