Decompiled source of BanditEncore v1.0.0

BanditEncore.dll

Decompiled 5 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using EntityStates;
using EntityStates.Bandit2.Weapon;
using R2API;
using RoR2;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName = ".NET Standard 2.0")]
[assembly: AssemblyCompany("BanditEncore")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0f72baeffeaabdf6f18986fa91ea66bb8b078778")]
[assembly: AssemblyProduct("BanditEncore")]
[assembly: AssemblyTitle("BanditEncore")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace BanditEncore;

[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInDependency(/*Could not decode attribute arguments.*/)]
[BepInPlugin("com.JohnGroton.BanditEncore", "BanditEncore", "1.0.0")]
public class BanditEncorePlugin : BaseUnityPlugin
{
	public static SkillDef desperadoChangeSkillDef;

	public const float damageCoefficient = 2f;

	public const float damagePerStack = 0.05f;

	public const float cooldown = 8f;

	public void Awake()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00cd: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
		//IL_0121: Unknown result type (might be due to invalid IL or missing references)
		//IL_0141: Unknown result type (might be due to invalid IL or missing references)
		//IL_014b: Expected O, but got Unknown
		//IL_014b: Unknown result type (might be due to invalid IL or missing references)
		//IL_014d: Unknown result type (might be due to invalid IL or missing references)
		Log.Init(((BaseUnityPlugin)this).Logger);
		SkillFamily skillFamily = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Bandit2/Bandit2Body.prefab").WaitForCompletion().GetComponent<SkillLocator>()
			.special.skillFamily;
		SkillDef val = FindSkill(skillFamily, typeof(PrepSidearmSkullRevolver));
		if ((Object)(object)val == (Object)null)
		{
			Log.Error("Couldn't find vanilla Desperado in Bandit's special skill family, skill not added");
			return;
		}
		LanguageAPI.Add("BANDIT_SPECIAL_NAME", "Encore");
		LanguageAPI.Add("BANDIT_SPECIAL_DESCRIPTION", $"<style=cIsDamage>Slayer</style>. Fire a revolver shot for <style=cIsDamage>{200f:0.##}% damage</style>. Kills with this skill permanently increase its damage by <style=cIsDamage>{5f:0.##}%</style>. Stacks last <style=cIsUtility>the entire run</style>.");
		SkillDef val2 = Object.Instantiate<SkillDef>(val);
		((Object)val2).name = "DesperadoChange";
		val2.skillName = "BANDIT_SPECIAL_NAME";
		val2.skillNameToken = "BANDIT_SPECIAL_NAME";
		val2.skillDescriptionToken = "BANDIT_SPECIAL_DESCRIPTION";
		val2.activationState = new SerializableEntityStateType(typeof(PrepEncore));
		val2.baseRechargeInterval = 8f;
		desperadoChangeSkillDef = val2;
		bool flag = default(bool);
		ContentAddition.AddEntityState<PrepEncore>(ref flag);
		ContentAddition.AddEntityState<FireEncore>(ref flag);
		ContentAddition.AddSkillDef(val2);
		Array.Resize(ref skillFamily.variants, skillFamily.variants.Length + 1);
		Variant[] variants = skillFamily.variants;
		int num = skillFamily.variants.Length - 1;
		Variant val3 = new Variant
		{
			skillDef = val2,
			unlockableDef = null
		};
		((Variant)(ref val3)).viewableNode = new Node(val2.skillNameToken, false, (Node)null);
		variants[num] = val3;
		PersistentSkulls.Init();
	}

	private static SkillDef FindSkill(SkillFamily skillFamily, Type activationStateType)
	{
		//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_0013: Unknown result type (might be due to invalid IL or missing references)
		//IL_0020: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Unknown result type (might be due to invalid IL or missing references)
		Variant[] variants = skillFamily.variants;
		foreach (Variant val in variants)
		{
			if (Object.op_Implicit((Object)(object)val.skillDef) && ((SerializableEntityStateType)(ref val.skillDef.activationState)).stateType == activationStateType)
			{
				return val.skillDef;
			}
		}
		return null;
	}
}
public class PrepEncore : PrepSidearmSkullRevolver
{
	public PrepEncore()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		VanillaFields.CopyFrom((EntityState)new PrepSidearmSkullRevolver(), (EntityState)(object)this);
	}

	public override EntityState GetNextState()
	{
		return (EntityState)(object)new FireEncore();
	}
}
public class FireEncore : FireSidearmSkullRevolver
{
	public FireEncore()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		//IL_0011: Expected O, but got Unknown
		VanillaFields.CopyFrom((EntityState)new FireSidearmSkullRevolver(), (EntityState)(object)this);
		((BaseFireSidearmRevolverState)this).damageCoefficient = 2f;
	}

	public override void ModifyBullet(BulletAttack bulletAttack)
	{
		((FireSidearmSkullRevolver)this).ModifyBullet(bulletAttack);
		int buffCount = ((EntityState)this).characterBody.GetBuffCount(Buffs.BanditSkull);
		bulletAttack.damage = ((BaseState)this).damageStat * ((BaseFireSidearmRevolverState)this).damageCoefficient * (1f + 0.05f * (float)buffCount);
	}
}
internal static class VanillaFields
{
	public static void CopyFrom(EntityState source, EntityState target)
	{
		Type type = ((object)source).GetType();
		while (type != null && type.Namespace == "EntityStates.Bandit2.Weapon")
		{
			FieldInfo[] fields = type.GetFields(BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
			foreach (FieldInfo fieldInfo in fields)
			{
				fieldInfo.SetValue(target, fieldInfo.GetValue(source));
			}
			type = type.BaseType;
		}
	}
}
internal static class Log
{
	private static ManualLogSource _logSource;

	internal static void Init(ManualLogSource logSource)
	{
		_logSource = logSource;
	}

	internal static void Debug(object data)
	{
		_logSource.LogDebug(data);
	}

	internal static void Error(object data)
	{
		_logSource.LogError(data);
	}

	internal static void Fatal(object data)
	{
		_logSource.LogFatal(data);
	}

	internal static void Info(object data)
	{
		_logSource.LogInfo(data);
	}

	internal static void Message(object data)
	{
		_logSource.LogMessage(data);
	}

	internal static void Warning(object data)
	{
		_logSource.LogWarning(data);
	}
}
public static class PersistentSkulls
{
	public static void Init()
	{
		CharacterBody.onBodyDestroyGlobal += SaveSkulls;
		CharacterBody.onBodyStartGlobal += RestoreSkulls;
	}

	private static void SaveSkulls(CharacterBody body)
	{
		if (NetworkServer.active && HasDesperadoChange(body) && Object.op_Implicit((Object)(object)body.master))
		{
			SkullTracker skullTracker = ((Component)body.master).GetComponent<SkullTracker>();
			if (!Object.op_Implicit((Object)(object)skullTracker))
			{
				skullTracker = ((Component)body.master).gameObject.AddComponent<SkullTracker>();
			}
			skullTracker.skullCount = body.GetBuffCount(Buffs.BanditSkull);
		}
	}

	private static void RestoreSkulls(CharacterBody body)
	{
		if (!NetworkServer.active || !HasDesperadoChange(body) || !Object.op_Implicit((Object)(object)body.master))
		{
			return;
		}
		SkullTracker component = ((Component)body.master).GetComponent<SkullTracker>();
		if (Object.op_Implicit((Object)(object)component))
		{
			int num = component.skullCount - body.GetBuffCount(Buffs.BanditSkull);
			for (int i = 0; i < num; i++)
			{
				body.AddBuff(Buffs.BanditSkull);
			}
		}
	}

	private static bool HasDesperadoChange(CharacterBody body)
	{
		SkillLocator skillLocator = body.skillLocator;
		if (Object.op_Implicit((Object)(object)skillLocator) && Object.op_Implicit((Object)(object)skillLocator.special))
		{
			return (Object)(object)skillLocator.special.baseSkill == (Object)(object)BanditEncorePlugin.desperadoChangeSkillDef;
		}
		return false;
	}
}
public class SkullTracker : MonoBehaviour
{
	public int skullCount;
}