using System; using System.Collections.Generic; 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.Bootstrap; using BepInEx.Configuration; using BepInEx.Logging; using IL.RoR2.Items; using Microsoft.CodeAnalysis; using Mono.Cecil.Cil; using MonoMod.Cil; using R2API; using R2API.Networking; using R2API.Networking.Interfaces; using RiskOfOptions; using RiskOfOptions.OptionConfigs; using RiskOfOptions.Options; using RoR2; using RoR2.Items; using UnityEngine; using UnityEngine.Networking; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("FaradaySpurTweaks")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+7446f2b9ac34a59aff285ee013e67ef66a29d9b5")] [assembly: AssemblyProduct("FaradaySpurTweaks")] [assembly: AssemblyTitle("FaradaySpurTweaks")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("1.0.0.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.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; } } } namespace FaradaySpurTweaks { [BepInPlugin("mwmw.FaradaySpurTweaks", "FaradaySpurTweaks", "1.0.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] [BepInDependency(/*Could not decode attribute arguments.*/)] public class FaradaySpurTweaks : BaseUnityPlugin { [CompilerGenerated] private static class <>O { public static Manipulator <0>__ChangeScalingRadius; public static Manipulator <1>__ChangeScalingDamage; public static Manipulator <2>__FixFPSDependency; } public const string PluginGUID = "mwmw.FaradaySpurTweaks"; public const string PluginAuthor = "mwmw"; public const string PluginName = "FaradaySpurTweaks"; public const string PluginVersion = "1.0.0"; public static ConfigFile config; public void Awake() { //IL_003a: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0045: Expected O, but got Unknown //IL_005b: 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 //IL_007c: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) //IL_0087: Expected O, but got Unknown Log.Init(((BaseUnityPlugin)this).Logger); config = ((BaseUnityPlugin)this).Config; Options.Init(); JumpDamageStrikeBodyBehavior.Init(); NetworkingAPI.RegisterMessageType(); object obj = <>O.<0>__ChangeScalingRadius; if (obj == null) { Manipulator val = ChangeScalingRadius; <>O.<0>__ChangeScalingRadius = val; obj = (object)val; } JumpDamageStrikeBodyBehavior.GetRadius += (Manipulator)obj; object obj2 = <>O.<1>__ChangeScalingDamage; if (obj2 == null) { Manipulator val2 = ChangeScalingDamage; <>O.<1>__ChangeScalingDamage = val2; obj2 = (object)val2; } JumpDamageStrikeBodyBehavior.DischargeEffects += (Manipulator)obj2; object obj3 = <>O.<2>__FixFPSDependency; if (obj3 == null) { Manipulator val3 = FixFPSDependency; <>O.<2>__FixFPSDependency = val3; obj3 = (object)val3; } JumpDamageStrikeBodyBehavior.FixedUpdate += (Manipulator)obj3; RoR2Application.onLoadFinished = (Action)Delegate.Combine(RoR2Application.onLoadFinished, new Action(OnLoadFinished)); Run.onRunStartGlobal += delegate { if (NetworkServer.active) { NetMessageExtensions.Send((INetMessage)(object)new SyncLanguage(Options.radiusGrowthPerStack.Value, Options.moveSpeedVelocityPerCharge.Value, Options.stackDamage.Value, Options.auraRadiusPerCharge.Value), (NetworkDestination)1); } }; Run.onRunDestroyGlobal += delegate { Options.UpdateLanguageTokensLocal(); }; } private void OnLoadFinished() { Options.OnLoadFinished(); } private static void ChangeScalingRadius(ILContext il) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown Func func = (float _) => Options.radiusGrowthPerStack.Value; ILCursor val = new ILCursor(il); float num = default(float); if (val.TryGotoNext(new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchSub(x) }) && val.TryGotoNext(new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchMul(x) }) && val.TryGotoNext((MoveType)2, new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, ref num) })) { val.EmitDelegate>(func); } else { Log.Error("ChangeRadius IL hook failed! Faraday Spur explosion radius cannnot be changed!"); } } private static void ChangeScalingDamage(ILContext il) { //IL_0022: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Expected O, but got Unknown Func func = (float _) => Options.stackDamage.Value; ILCursor val = new ILCursor(il); float num2 = default(float); float num = default(float); if (val.TryGotoNext(new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, "get_active") }) && val.TryGotoNext(new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, ref num2) }) && val.TryGotoNext((MoveType)2, new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, ref num) })) { val.EmitDelegate>(func); } else { Log.Error("ChangeScalingDamage IL hook failed! Faraday Spur scaling damage cannot be changed!"); } } private static void FixFPSDependency(ILContext il) { //IL_0048: Unknown result type (might be due to invalid IL or missing references) //IL_004e: Expected O, but got Unknown //IL_00ac: Unknown result type (might be due to invalid IL or missing references) //IL_00c0: Unknown result type (might be due to invalid IL or missing references) Func func = (float _) => -1f; Func func2 = (JumpDamageStrikeBodyBehavior behaviour) => ((Vector3)(ref behaviour.motor.velocity)).magnitude > 0.5f; ILCursor val = new ILCursor(il); ILLabel skipLabel = null; if (val.TryGotoNext(new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchCallOrCallvirt(x, "get_isGrounded") }) && val.TryGotoNext((MoveType)2, new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchBrfalse(x, ref skipLabel) })) { val.Emit(OpCodes.Ldarg_0); val.EmitDelegate>(func2); val.Emit(OpCodes.Brfalse, (object)skipLabel); if (val.TryGotoNext((MoveType)2, new Func[1] { (Instruction x) => ILPatternMatchingExt.MatchLdcR4(x, 0.5f) })) { val.EmitDelegate>(func); } else { Log.Error("Part 2 of FixFPSDependency IL hook failed!"); } } else { Log.Error("Part 1 of FixFPSDependency IL hook failed!"); } } } public class SyncLanguage : INetMessage, ISerializableObject { private float radiusGrowthPerStack; private float moveSpeedVelocityPerCharge; private float stackDamage; private float auraRadiusPerCharge; public SyncLanguage() { } public SyncLanguage(float radiusGrowthPerStack, float moveSpeedVelocityPerCharge, float stackDamage, float auraRadiusPerCharge) { this.radiusGrowthPerStack = radiusGrowthPerStack; this.moveSpeedVelocityPerCharge = moveSpeedVelocityPerCharge; this.stackDamage = stackDamage; this.auraRadiusPerCharge = auraRadiusPerCharge; } public void Serialize(NetworkWriter writer) { writer.Write(radiusGrowthPerStack); writer.Write(moveSpeedVelocityPerCharge); writer.Write(stackDamage); writer.Write(auraRadiusPerCharge); } public void Deserialize(NetworkReader reader) { radiusGrowthPerStack = reader.ReadSingle(); moveSpeedVelocityPerCharge = reader.ReadSingle(); stackDamage = reader.ReadSingle(); auraRadiusPerCharge = reader.ReadSingle(); } public void OnReceived() { Options.UpdateLanguageTokens(radiusGrowthPerStack, moveSpeedVelocityPerCharge, stackDamage, auraRadiusPerCharge); } } 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 class Options { private static bool? _rooEnabled; public static BindingFlags allFlags = BindingFlags.DeclaredOnly | BindingFlags.Instance | BindingFlags.Static | BindingFlags.Public | BindingFlags.NonPublic; private static LanguageOverlay languageOverlay; public static bool rooEnabled { get { if (!_rooEnabled.HasValue) { _rooEnabled = Chainloader.PluginInfos.ContainsKey("com.rune580.riskofoptions"); } return _rooEnabled.Value; } } public static ConfigEntry radiusGrowthPerStack { get; set; } public static ConfigEntry moveSpeedVelocityPerCharge { get; set; } public static ConfigEntry stackDamage { get; set; } public static ConfigEntry auraRadiusPerCharge { get; set; } private static void UpdateLanguageTokensServer() { if ((Object)(object)Run.instance != (Object)null && NetworkServer.active) { NetMessageExtensions.Send((INetMessage)(object)new SyncLanguage(radiusGrowthPerStack.Value, moveSpeedVelocityPerCharge.Value, stackDamage.Value, auraRadiusPerCharge.Value), (NetworkDestination)1); } else if ((Object)(object)Run.instance == (Object)null) { UpdateLanguageTokens(radiusGrowthPerStack.Value, moveSpeedVelocityPerCharge.Value, stackDamage.Value, auraRadiusPerCharge.Value); } } public static void UpdateLanguageTokensLocal() { UpdateLanguageTokens(radiusGrowthPerStack.Value, moveSpeedVelocityPerCharge.Value, stackDamage.Value, auraRadiusPerCharge.Value); } public static void UpdateLanguageTokens(float radiusGrowthPerStack, float moveSpeedVelocityPerCharge, float stackDamage, float auraRadiusPerCharge) { LanguageOverlay obj = languageOverlay; if (obj != null) { obj.Remove(); } Dictionary dictionary = new Dictionary(); dictionary.Add("ITEM_JUMPDAMAGESTRIKE_DESC", string.Format("Moving around builds up charge, granting up to +{0}% movement speed and +200% jump height at 100%. At 25% charge or higher, jumping triggers an explosive discharge for 400% (+{1}% per stack) damage in a 5m to {2}m (+{3}m per stack) area.", (int)(moveSpeedVelocityPerCharge * 10000f), (int)(stackDamage * 100f), (auraRadiusPerCharge * 99f + radiusGrowthPerStack + 5f).ToString("0.#"), radiusGrowthPerStack)); dictionary.Add("ITEM_JUMPDAMAGESTRIKE_UNCOMMON_DESC", string.Format("Moving around builds up charge, granting up to +{0}% movement speed and +200% jump height at 100%. At 25% charge or higher, jumping consumes 75% charge and triggers an explosive discharge for 400% (+{1}% per stack) damage, plus an additional 150% (+150% per stack) damage for every 100% movement speed, in a 5m to {2}m (+{3}m per stack) area.", (int)(moveSpeedVelocityPerCharge * 10000f), (int)(stackDamage * 100f), (auraRadiusPerCharge * 99f + radiusGrowthPerStack + 5f).ToString("0.#"), radiusGrowthPerStack)); dictionary.Add("ITEM_JUMPDAMAGESTRIKE_RARE_DESC", string.Format("Moving around builds up charge, granting up to +{0}% movement speed and +200% jump height at 100%. At 25% charge or higher, jumping consumes 50% charge and triggers an explosive discharge for 400% (+{1}% per stack) damage, plus an additional 250% (+250% per stack) damage for every 100% movement speed, in a 5m to {2}m (+{3}m per stack) area.", (int)(moveSpeedVelocityPerCharge * 10000f), (int)(stackDamage * 100f), (auraRadiusPerCharge * 99f + radiusGrowthPerStack + 5f).ToString("0.#"), radiusGrowthPerStack)); dictionary.Add("ITEM_JUMPDAMAGESTRIKE_EPIC_DESC", string.Format("Moving around builds up charge, granting up to +{0}% movement speed and +200% jump height at 100%. At 25% charge or higher, jumping consumes 25% charge and triggers an explosive discharge for 400% (+{1}% per stack) damage, plus an additional 350% (+350% per stack) damage for every 100% movement speed, in a 5m to {2}m (+{3}m per stack) area.", (int)(moveSpeedVelocityPerCharge * 10000f), (int)(stackDamage * 100f), (auraRadiusPerCharge * 99f + radiusGrowthPerStack + 5f).ToString("0.#"), radiusGrowthPerStack)); dictionary.Add("ITEM_JUMPDAMAGESTRIKE_LEGENDARY_DESC", string.Format("Moving around builds up charge, granting up to +{0}% movement speed and +200% jump height at 100%. At 25% charge or higher, jumping consumes 10% charge and triggers an explosive discharge for 400% (+{1}% per stack) damage, plus an additional 500% (+500% per stack) damage for every 100% movement speed, in a 5m to {2}m (+{3}m per stack) area.", (int)(moveSpeedVelocityPerCharge * 10000f), (int)(stackDamage * 100f), (auraRadiusPerCharge * 99f + radiusGrowthPerStack + 5f).ToString("0.#"), radiusGrowthPerStack)); languageOverlay = LanguageAPI.AddOverlay(dictionary); } public static void Init() { radiusGrowthPerStack = FaradaySpurTweaks.config.Bind("Faraday Spur", "Radius Growth Per Stack", 10f, "How much the maximum explosion radius grows for each additional stack of the item you have."); radiusGrowthPerStack.SettingChanged += delegate { UpdateLanguageTokensServer(); }; moveSpeedVelocityPerCharge = FaradaySpurTweaks.config.Bind("Faraday Spur", "Move Speed Velocity Per Charge", 0.003f, "How much movement speed you gain for each percentage of charge you have."); moveSpeedVelocityPerCharge.SettingChanged += delegate { typeof(JumpDamageStrikeBodyBehavior).GetField("MoveSpeedVelocityPerCharge", allFlags).SetValue(null, moveSpeedVelocityPerCharge.Value); UpdateLanguageTokensServer(); }; stackDamage = FaradaySpurTweaks.config.Bind("Faraday Spur", "Stack Damage", 3f, "How the explosion damage grows for each additional stack of the item you have"); stackDamage.SettingChanged += delegate { UpdateLanguageTokensServer(); }; auraRadiusPerCharge = FaradaySpurTweaks.config.Bind("Faraday Spur", "Aura Radius Per Charge", 0.20202f, "How much movement the explosion radius grows for each percentage of charge you have."); auraRadiusPerCharge.SettingChanged += delegate { typeof(JumpDamageStrikeBodyBehavior).GetField("auraRadiusPerCharge", allFlags).SetValue(null, auraRadiusPerCharge.Value); UpdateLanguageTokensServer(); }; if (rooEnabled) { RoOInit(); } } private static void RoOInit() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_000b: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) //IL_0031: Expected O, but got Unknown //IL_002c: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Expected O, but got Unknown //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_0067: Expected O, but got Unknown //IL_0062: Unknown result type (might be due to invalid IL or missing references) //IL_006c: Expected O, but got Unknown //IL_0072: Unknown result type (might be due to invalid IL or missing references) //IL_0077: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Unknown result type (might be due to invalid IL or missing references) //IL_008d: Unknown result type (might be due to invalid IL or missing references) //IL_009d: Expected O, but got Unknown //IL_0098: Unknown result type (might be due to invalid IL or missing references) //IL_00a2: Expected O, but got Unknown //IL_00a8: Unknown result type (might be due to invalid IL or missing references) //IL_00ad: Unknown result type (might be due to invalid IL or missing references) //IL_00b8: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00d3: Expected O, but got Unknown //IL_00ce: Unknown result type (might be due to invalid IL or missing references) //IL_00d8: Expected O, but got Unknown ModSettingsManager.AddOption((BaseOption)new StepSliderOption(radiusGrowthPerStack, new StepSliderConfig { min = 0f, max = 1000f, increment = 0.1f })); ModSettingsManager.AddOption((BaseOption)new StepSliderOption(moveSpeedVelocityPerCharge, new StepSliderConfig { min = 0f, max = 100f, increment = 0.0001f })); ModSettingsManager.AddOption((BaseOption)new StepSliderOption(stackDamage, new StepSliderConfig { min = 0f, max = 100f, increment = 0.01f })); ModSettingsManager.AddOption((BaseOption)new StepSliderOption(auraRadiusPerCharge, new StepSliderConfig { min = 0f, max = 100f, increment = 0.001f })); ModSettingsManager.SetModDescription("Config options for certain aspects of Faraday Spur."); } public static void OnLoadFinished() { typeof(JumpDamageStrikeBodyBehavior).GetField("auraRadiusPerCharge", allFlags).SetValue(null, auraRadiusPerCharge.Value); typeof(JumpDamageStrikeBodyBehavior).GetField("MoveSpeedVelocityPerCharge", allFlags).SetValue(null, moveSpeedVelocityPerCharge.Value); UpdateLanguageTokensServer(); } } }