Decompiled source of Artifixer v1.2.0

ExamplePlugin.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using EntityStates.Mage.Weapon;
using Microsoft.CodeAnalysis;
using On.EntityStates.Mage.Weapon;
using On.RoR2;
using RoR2;
using RoR2.Skills;
using UnityEngine;
using UnityEngine.AddressableAssets;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("ExamplePlugin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("ExamplePlugin")]
[assembly: AssemblyTitle("ExamplePlugin")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Embedded]
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
[BepInPlugin("TheEye.artificertweaks", "Artifixer", "1.1.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class ArtificerTweaks : BaseUnityPlugin
{
	private static readonly FieldInfo leftTransformField = typeof(Flamethrower).GetField("leftFlamethrowerTransform", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly FieldInfo rightTransformField = typeof(Flamethrower).GetField("rightFlamethrowerTransform", BindingFlags.Instance | BindingFlags.NonPublic);

	private static readonly ConditionalWeakTable<Transform, object> tweakedEffects = new ConditionalWeakTable<Transform, object>();

	private static readonly string[] targetEffectNames = new string[2] { "FireForward", "FireForward (1)" };

	private static ConfigEntry<float> rangeMultiplierCfg;

	private static ConfigEntry<float> stiffnessCfg;

	private static ConfigEntry<float> dampingCfg;

	private static ConfigEntry<float> elasticityCfg;

	private static ConfigEntry<float> inertCfg;

	private static ConfigEntry<float> sizeMultiplierCfg;

	private static ConfigEntry<float> lineWidthMultiplierCfg;

	private void Awake()
	{
		//IL_002e: Unknown result type (might be due to invalid IL or missing references)
		//IL_0038: Expected O, but got Unknown
		//IL_006b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0075: Expected O, but got Unknown
		//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b2: Expected O, but got Unknown
		//IL_00e5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00ef: Expected O, but got Unknown
		//IL_0122: Unknown result type (might be due to invalid IL or missing references)
		//IL_012c: Expected O, but got Unknown
		//IL_015f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0169: Expected O, but got Unknown
		//IL_019c: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a6: Expected O, but got Unknown
		//IL_01b2: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bc: Expected O, but got Unknown
		//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
		//IL_01cd: Expected O, but got Unknown
		//IL_01d4: Unknown result type (might be due to invalid IL or missing references)
		//IL_01de: Expected O, but got Unknown
		rangeMultiplierCfg = ((BaseUnityPlugin)this).Config.Bind<float>("Flamethrower", "RangeMultiplier", 3f, new ConfigDescription("Multiplies both damage range and visual length.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(1f, 5f), Array.Empty<object>()));
		stiffnessCfg = ((BaseUnityPlugin)this).Config.Bind<float>("Flamethrower", "Stiffness", 0.97f, new ConfigDescription("Higher = more rigid/laser-like, less bendy.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		dampingCfg = ((BaseUnityPlugin)this).Config.Bind<float>("Flamethrower", "Damping", 1f, new ConfigDescription("Higher = settles faster, less wobble/oscillation.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		elasticityCfg = ((BaseUnityPlugin)this).Config.Bind<float>("Flamethrower", "Elasticity", 0.8f, new ConfigDescription("Higher = springier/bouncier motion.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		inertCfg = ((BaseUnityPlugin)this).Config.Bind<float>("Flamethrower", "Inert", 0f, new ConfigDescription("Higher = ignores sudden aim movement more (more lag on fast turns).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
		sizeMultiplierCfg = ((BaseUnityPlugin)this).Config.Bind<float>("Flamethrower", "ThicknessMultiplier", 2.5f, new ConfigDescription("Multiplies the flame particle stream's visual thickness (may have limited visible effect).", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>()));
		lineWidthMultiplierCfg = ((BaseUnityPlugin)this).Config.Bind<float>("Flamethrower", "LineWidthMultiplier", 2.4f, new ConfigDescription("Multiplies the visible beam's line thickness.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 5f), Array.Empty<object>()));
		Flamethrower.OnEnter += new hook_OnEnter(Flamethrower_OnEnter);
		Flamethrower.FixedUpdate += new hook_FixedUpdate(Flamethrower_FixedUpdate);
		SurvivorCatalog.Init += new hook_Init(SurvivorCatalog_Init);
	}

	private void Flamethrower_OnEnter(orig_OnEnter orig, Flamethrower self)
	{
		self.maxDistance *= rangeMultiplierCfg.Value;
		orig.Invoke(self);
	}

	private void Flamethrower_FixedUpdate(orig_FixedUpdate orig, Flamethrower self)
	{
		orig.Invoke(self);
		object? value = leftTransformField.GetValue(self);
		Transform effectTransform = (Transform)((value is Transform) ? value : null);
		object? value2 = rightTransformField.GetValue(self);
		Transform effectTransform2 = (Transform)((value2 is Transform) ? value2 : null);
		TryTweakOnce(effectTransform);
		TryTweakOnce(effectTransform2);
	}

	private void TryTweakOnce(Transform effectTransform)
	{
		//IL_0091: Unknown result type (might be due to invalid IL or missing references)
		//IL_0102: Unknown result type (might be due to invalid IL or missing references)
		//IL_0107: Unknown result type (might be due to invalid IL or missing references)
		//IL_0168: Unknown result type (might be due to invalid IL or missing references)
		//IL_016d: Unknown result type (might be due to invalid IL or missing references)
		if (!Object.op_Implicit((Object)(object)effectTransform) || tweakedEffects.TryGetValue(effectTransform, out var _))
		{
			return;
		}
		DynamicBone component = ((Component)effectTransform).GetComponent<DynamicBone>();
		if (Object.op_Implicit((Object)(object)component))
		{
			component.m_Stiffness = stiffnessCfg.Value;
			component.m_Damping = dampingCfg.Value;
			component.m_Elasticity = elasticityCfg.Value;
			component.m_Inert = inertCfg.Value;
		}
		Transform val = effectTransform.Find("Bone1");
		if (Object.op_Implicit((Object)(object)val))
		{
			val.localScale = new Vector3(1f, 1f, rangeMultiplierCfg.Value);
			LineRenderer component2 = ((Component)val).GetComponent<LineRenderer>();
			if (Object.op_Implicit((Object)(object)component2))
			{
				component2.widthMultiplier *= lineWidthMultiplierCfg.Value;
			}
		}
		string[] array = targetEffectNames;
		foreach (string name in array)
		{
			Transform val2 = FindDeepChild(effectTransform, name);
			if (Object.op_Implicit((Object)(object)val2))
			{
				ParticleSystem component3 = ((Component)val2).GetComponent<ParticleSystem>();
				if (Object.op_Implicit((Object)(object)component3))
				{
					MainModule main = component3.main;
					component3.Stop();
					component3.Clear();
					((MainModule)(ref main)).simulationSpace = (ParticleSystemSimulationSpace)0;
					((MainModule)(ref main)).startSize3D = true;
					((MainModule)(ref main)).startSizeXMultiplier = ((MainModule)(ref main)).startSizeXMultiplier * sizeMultiplierCfg.Value;
					((MainModule)(ref main)).startSizeYMultiplier = ((MainModule)(ref main)).startSizeYMultiplier * sizeMultiplierCfg.Value;
					((MainModule)(ref main)).startColor = new MinMaxGradient(new Color(0.4f, 0.7f, 1f));
					component3.Play();
				}
			}
		}
		tweakedEffects.Add(effectTransform, null);
	}

	private Transform FindDeepChild(Transform parent, string name)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		foreach (Transform item in parent)
		{
			Transform val = item;
			if (((Object)val).name == name)
			{
				return val;
			}
			Transform val2 = FindDeepChild(val, name);
			if (Object.op_Implicit((Object)(object)val2))
			{
				return val2;
			}
		}
		return null;
	}

	private void SurvivorCatalog_Init(orig_Init orig)
	{
		orig.Invoke();
		AllowSprintDuringArtificerSkills();
	}

	private void AllowSprintDuringArtificerSkills()
	{
		//IL_0005: Unknown result type (might be due to invalid IL or missing references)
		//IL_000a: Unknown result type (might be due to invalid IL or missing references)
		SkillLocator component = Addressables.LoadAssetAsync<GameObject>((object)"RoR2/Base/Mage/MageBody.prefab").WaitForCompletion().GetComponent<SkillLocator>();
		FixSkill(component.primary);
		FixSkill(component.secondary);
		FixSkill(component.utility);
		FixSkill(component.special);
	}

	private void FixSkill(GenericSkill skillSlot)
	{
		//IL_0012: Unknown result type (might be due to invalid IL or missing references)
		Variant[] variants = skillSlot.skillFamily.variants;
		for (int i = 0; i < variants.Length; i++)
		{
			variants[i].skillDef.canceledFromSprinting = false;
		}
	}
}
namespace ExamplePlugin
{
	internal static class Log
	{
		private static ManualLogSource _logSource;

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

		private static string Format(object data, string file, int line)
		{
			string fileName = Path.GetFileName(file);
			return $"[{fileName}:{line}] {data}";
		}

		internal static void Debug(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogDebug((object)Format(data, file, line));
		}

		internal static void Error(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogError((object)Format(data, file, line));
		}

		internal static void Fatal(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogFatal((object)Format(data, file, line));
		}

		internal static void Info(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogInfo((object)Format(data, file, line));
		}

		internal static void Message(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogMessage((object)Format(data, file, line));
		}

		internal static void Warning(object data, [CallerFilePath] string file = "", [CallerLineNumber] int line = 0)
		{
			_logSource.LogWarning((object)Format(data, file, line));
		}
	}
}